import { createModel } from '@rematch/core'

import { User } from '../../types/user'

import { RootModel } from '.'


const defaultState = (): User => null

export const user = createModel<RootModel>()({
  state: defaultState(),
  reducers: {
    updateUser(state, user: User) {
      return {
        ...state,
        ...user,
        traits: {
          ...state?.traits,
          ...user?.traits
        }
      }
    }
  },
  effects: {}
})
