import {
    AuthAction,
    AuthState,
  } from './auth.interface';
  
  export const initialState: AuthState = {
    userName: '',
    token: '',
    isLogin: false,
    authType: 'login',
    userPhone: ''
  };
  
  export const reducer = (state: AuthState, action: AuthAction) => {
    switch (action.type) {
      case "login": {
        const { userName, token, userPhone } = action.payload.data;
        return {
          ...state,
          userName,
          token,
          isLogin: true,
          userPhone
        };
      }
  
      case "logout": {
        return initialState;
      }
  
      case "change password": {
        return state;
      }

      case "switch auth type": {
        const { authType } = action.payload.data;
        return {
          ...state,
          authType
        }
      }  
  
      default:
        return state;
    }
  };
  