import { create } from 'zustand';
import { persist } from 'zustand/middleware';

interface AuthState {
  userId?: number;
  loginId?: string;
  userName?: string;
  roles: string[];
  setAuth: (data: { userId: number; loginId: string; userName: string; roles: string[] }) => void;
  clear: () => void;
}

export const useAuthStore = create<AuthState>()(
  persist(
    (set) => ({
      roles: [],
      setAuth: (d) => set({ ...d }),
      clear: () => set({ userId: undefined, loginId: undefined, userName: undefined, roles: [] }),
    }),
    { name: 'ga-auth' },
  ),
);
