import { Action } from 'redux';

import { UserInfo } from '@/types/user';

import { SET_USER_INFO, SET_BIND_PHONE } from '../constants';

const INIT_STATE: Partial<UserInfo> = {};

const userInfo = (state: Partial<UserInfo> = INIT_STATE, action: Action): Partial<UserInfo> => {
  const { type, value } = action as BL.Anything;
  switch (type) {
    case SET_USER_INFO: {
      const newUserInfo: Partial<UserInfo> = { ...state, ...value };
      return newUserInfo;
    }
    case SET_BIND_PHONE: {
      const newUserInfo: Partial<UserInfo> = { ...state, isBindPhone: value };
      return newUserInfo;
    }
    default:
      return state;
  }
};

export default userInfo;
