import { createReducer } from '@reduxjs/toolkit';
import { IMessagesState, IMessagesPayload} from '../../../typescript/redux/messages/interfaces';
import {
  actionGetMessagesSuccess,
  actionGetMessagesReject
} from '../action';

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

const reducerMessages = createReducer(initialState, {
  [actionGetMessagesSuccess.type]: (_, { payload }: IMessagesPayload) => {
    return payload;
  },
  [actionGetMessagesReject.type]: (state, _) => {
    return state;
  },
});

export default reducerMessages;
