import { makeAutoObservable } from 'mobx'
import storage from '../utils/storage'
import { Token, UserInfo } from '../constants/storage'

export interface IUserInfo {
	firstName: string
	lastName: string
	gender: number
	email: string
}

export class AuthStore {
	static singleton: AuthStore | null = null

	static instance() {
		if (!AuthStore.singleton) {
			AuthStore.singleton = new AuthStore()
		}
		return AuthStore.singleton
	}

	constructor() {
		makeAutoObservable(this)
	}

	get token(): string | null {
		return storage.get<string>(Token)
	}

	get userInfo(): IUserInfo | null {
		return storage.get(UserInfo)
	}

	get userName(): string {
		if (!this.userInfo) {
			return ''
		}
		return [this.userInfo.firstName, this.userInfo.lastName].join(' ')
	}

	get logined() {
		console.log(this.token)
		return !!this.token
	}

	register() {}

	login() {}

	getUserInfo() {}

	resetPassword() {}
}
