import { createReducer } from '@reduxjs/toolkit';
import { IContactsState,IContactsPayload} from '../../../typescript/redux/contacts/interfaces';
import {
  actionGetContactsSuccess,
  actionGetContactsReject
} from '../action';

const initialState:IContactsState = {
  total: "0",
  limit: "0",
  page: "0",
  contacts: []
}

const reducerContacts = createReducer(initialState, {
  [actionGetContactsSuccess.type]: (_state,{ payload}:IContactsPayload) => {
    return payload;
  },
  [actionGetContactsReject.type]: (state, _) => {
    return state;
  },
});

export default reducerContacts;
