import { create } from "zustand";
import { clearAuthSessionHint, markAuthSessionHint } from "@modules/auth/store/authSessionHint";

export type UserRole = "user" | "admin";
export type UserStatus = "active" | "pending" | "blocked";

export interface AuthUser {
  id: string;
  email: string;
  role: UserRole;
  is_superuser: boolean;
  status: UserStatus;
}

interface AuthState {
  accessToken: string | null;
  user: AuthUser | null;
  bootstrapped: boolean;
  setSession: (accessToken: string, user: AuthUser) => void;
  clearSession: () => void;
  setBootstrapped: (bootstrapped: boolean) => void;
}

export const useAuthStore = create<AuthState>()((set) => ({
  accessToken: null,
  user: null,
  bootstrapped: false,
  setSession: (accessToken, user) => {
    markAuthSessionHint();
    set({ accessToken, user });
  },
  clearSession: () => {
    clearAuthSessionHint();
    set({ accessToken: null, user: null });
  },
  setBootstrapped: (bootstrapped) => set({ bootstrapped })
}));
