import {
  Actions,
  ActionType,
} from './regist.action';

import {
  State,
  initialState,
} from './regist.state';

import { DiscoveryStartInfo } from '@overflow/commons-typescript/model/discovery';

export function reducer(state = initialState, action: Actions): State {
  switch (action.type) {
    case ActionType.SaveAllTarget: {
      return {
        ...state,
        error: null,
        isPending: true,
      };
    }

    case ActionType.SaveAllTargetSuccess: {
      return {
        ...state,
        error: null,
        isPending: false,
        isSuccess: action.payload,
      };
    }

    case ActionType.SaveAllTargetFailure: {
      return {
        ...state,
        error: action.payload,
        isPending: false,
        isSuccess: null,
      };
    }

    default: {
      return state;
    }
  }
}