import * as ActionTypes from '../actionTypes'
import { UserDispatchTypes, UserState } from './types'

const initialState: UserState = {
  robotImage: null,
  profile: null
}

const reducer = (
  state = initialState,
  action: UserDispatchTypes
): UserState => {
  switch (action.type) {
    case ActionTypes.SET_USER_ROBOT_IMAGE:
      return {
        ...state,
        robotImage: action.payload
      }

    case ActionTypes.SET_USER_PROFILE:
      return {
        ...state,
        profile: action.payload
      }

    case ActionTypes.RESTORE_STATE:
      return action.payload.user || initialState

    default:
      return state
  }
}

export default reducer
