import { create } from 'zustand'
import type { CurrentUser } from '@/shared/api/types'

type AuthState = {
  user: CurrentUser | null
  /** Пока не завершилась попытка тихого восстановления сессии при старте приложения. */
  isBootstrapping: boolean
  setUser: (user: CurrentUser | null) => void
  finishBootstrap: () => void
}

export const useAuthStore = create<AuthState>((set) => ({
  user: null,
  isBootstrapping: true,
  setUser: (user) => set({ user }),
  finishBootstrap: () => set({ isBootstrapping: false }),
}))
