import { defineStore } from 'pinia'
import { store } from '@/stores'

interface UserState {
  access_token: string
  tenant_id: string
  pushRecordId: string
  needFaceId: boolean
}

export const useUserStore = defineStore('user', {
  state: (): UserState => ({
    access_token: '',
    tenant_id: '1',
    pushRecordId: '',
    needFaceId: false,
  }),

  actions: {
    setAccessToken(token: string) {
      this.access_token = token
    },
    setPushRecordId(id: string) {
      this.pushRecordId = id
    },
    setNeedFaceId(flag: boolean) {
      this.needFaceId = flag
    },
    LogOut() {
      this.access_token = ''
      this.needFaceId = false
    },
  },

  persist: {
    key: 'user-store',
    storage: sessionStorage,
    pick: ['access_token', 'needFaceId', 'tenant_id', 'pushRecordId'],
  },
})

export function useUserStoreWithOut() {
  return useUserStore(store)
}
