import { createReducer } from '@reduxjs/toolkit';
import { IAllMessagesState, IAllMessagesPayload} from '../../../typescript/redux/allMessages/interfaces';
import {
  actionGetAllMessagesSuccess,
  actionGetAllMessagesReject,
} from '../action';

const initialState: IAllMessagesState = {
  total: "0",
  limit: "0",
  page: "0",
  messages: [],
}

const reducerAllMessages = createReducer(initialState, {
  [actionGetAllMessagesSuccess.type]: (_, { payload }: IAllMessagesPayload) => {
    return payload;
  },
  [actionGetAllMessagesReject.type]: (state, _) => {
    return state;
  },
});

export default reducerAllMessages;
