import Action from '../../types/Store/Actions';
import { Customer, CustomerSex } from '../../types/Customer/Customer';

export type UserState = StoreState<Customer & { code: string }>;

export const INITIAL_STATE = {
  code: '',
  areaId: 0,
  areaName: '',
  birthDay: '',
  createAt: '',
  createLoginDate: '',
  customerHead: '',
  customerId: 0,
  customerName: '',
  customerPhone: '',
  customerSex: CustomerSex.boy,
  customerType: '',
  email: '',
  entranceDate: '',
  hardwareAccount: '',
  hardwarePwd: '',
  hardwareState: '',
  hardwarelastDate: '',
  idBar: '',
  idCard: '',
  isFirstRecharge: 0,
  lastLoginDate: '',
  loginAccount: '',
  loginPwd: '',
  loginPwdSalt: '',
  loginState: '',
  state: '',
  studentNo: '',
  token: '',
  updateAt: '',
  updateLoginDate: '',
  version: '',
};

export const updateUserInfo = (entity: UserState): Action => ({
  type: 'UPDATE_USERINFO',
  payload: entity,
});

export default function userinfo(
  state: Customer = INITIAL_STATE,
  actions: Action,
): Customer {
  switch (actions.type) {
    case 'UPDATE_USERINFO':
      return {
        ...state,
        ...actions.payload,
      };
    default:
      return state;
  }
}
