import { combineReducers } from 'redux';
import { getSuccessActionType } from '../utils';
import { getErrorReducer, getStatusReducer } from './utils/generators';
import { FETCH_CARDS } from '../constants/card';

function data(state = {}, action) {
  switch (action.type) {
    case getSuccessActionType(FETCH_CARDS):
      return action.payload.data;

    default:
      return state;
  }
}

function count(state = 0, action) {
  switch (action.type) {
    case getSuccessActionType(FETCH_CARDS):
      return action.payload.count;

    default:
      return state;
  }
}

function pageCount(state = 1, action) {
  switch (action.type) {
    case getSuccessActionType(FETCH_CARDS):
      return action.payload.pageCount;

    default:
      return state;
  }
}

export default combineReducers({
  status: getStatusReducer([FETCH_CARDS]),
  error: getErrorReducer([FETCH_CARDS]),
  data,
  count,
  pageCount
});
