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.ReadAllByDisplayItem: {
      return {
        ...state,
        error: null,
        pending: true,
      };
    }

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

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

    default: {
      return state;
    }
  }
}
