import { Action } from 'redux';

import { SET_USER_MESSAGE } from '@/store/constants';
import { UserMessage } from '@/types/message';

const INIT_STATE: Partial<UserMessage> = {
  count: 0,
};

const message = (state: Partial<UserMessage> = INIT_STATE, action: Action): Partial<UserMessage> => {
  const { type, value } = action as BL.Anything;
  switch (type) {
    case SET_USER_MESSAGE: {
      const newValue: Partial<UserMessage> = { ...state, ...value };
      return newValue;
    }
    default:
      return state;
  }
};

export default message;
