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

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

  import { Target } from '../../model';

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

      case ActionType.ReadAllByDomainSuccess: {
        return {
          ...state,
          error: null,
          pending: false,
          targets: action.payload
        };
      }

      case ActionType.ReadAllByDomainFailure: {
        return {
          ...state,
          error: action.payload,
          pending: false,
          targets: null,
        };
      }

      default: {
        return state;
      }
    }
  }
