import { SET_CURRENT_USER, UPDATE_USER, START_FETCH_USER } from '@/store/userAction';
import { merge } from 'lodash'


const initialState = {
    hasError: false,
    msg: '',
    data: {
        username: '',
        avatar: '',
        isVip: false,
        token: '',
        email: '',
        uid: ''
    },
    isFetching: true
}


export default function (state = initialState, action) {
    switch (action.type) {
        case SET_CURRENT_USER:
            return action.payload
        case UPDATE_USER:
            return merge({}, state, action.payload)
        case START_FETCH_USER:
            return {...state, isFetching: true}
        default:
            return state
    }
}