import { combineReducers } from 'redux';
import { getSuccessActionType } from '../utils';
import { getErrorReducer, getStatusReducer } from './utils/generators';
import { CREATE_PAYMENT, FETCH_PAYMENT } from '../constants/payment';

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

    default:
      return state;
  }
}

const actionTypes = [FETCH_PAYMENT, CREATE_PAYMENT];

export default combineReducers({
  status: getStatusReducer(actionTypes),
  error: getErrorReducer(actionTypes),
  data
});
