import isEqual from 'lodash.isequal';
import { createReducer } from '@reduxjs/toolkit';
import { IChatsState, IChatsPayload } from '../../../typescript/redux/chats/interfaces';

import {
  actionGetChatsSuccess,
  actionGetChatsReject,
} from '../action';

const initialState: IChatsState = {
  total: "0",
  limit: "0",
  page: "0",
  chats: [],
}



const reducerChats = createReducer(initialState, {
  [actionGetChatsSuccess.type]: (state, { payload }: IChatsPayload) => {
    if (isEqual(state, payload) === false) return payload
    return state;
  },
  [actionGetChatsReject.type]: (state, _payload) => {
    return state;
  },
});

export default reducerChats;
