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

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

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

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

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

    default: {
      return state;
    }
  }
}
