import isEqual from 'lodash.isequal';
import { createReducer } from '@reduxjs/toolkit';
import { IPinnedMessagesPayload} from '../../../typescript/redux/pinnedMessages/interfaces';
import { TPinnedMessages} from '../../../typescript/redux/pinnedMessages/types';
import {
  actionGetPinnedMessagesSuccess,
  actionGetPinnedMessagesReject,
} from '../action';

const initialState: TPinnedMessages = []

const reducerPinnedMessages = createReducer(initialState, {
  [actionGetPinnedMessagesSuccess.type]: (state, { payload }: IPinnedMessagesPayload) => {
    if (isEqual(state, payload) === false) return payload
    return state;
  },
  [actionGetPinnedMessagesReject.type]: (state, _payload) => {
    return state;
  },
});

export default reducerPinnedMessages;
