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

export type UserRole = 'SystemAdmin' | 'Manager' | 'User' | 'Guest';

interface DemoState {
  userRole: UserRole;
  companyName: string;
  userName: string;
  setUserRole: (role: UserRole) => void;
  setCompanyName: (name: string) => void;
  setUserName: (name: string) => void;
  resetDemo: () => void;
}

const DEFAULT_STATE = {
  userRole: 'Manager' as UserRole,
  companyName: 'SAM 데모 회사',
  userName: '홍길동',
};

export const useDemoStore = create<DemoState>()(
  persist(
    (set) => ({
      ...DEFAULT_STATE,

      setUserRole: (role: UserRole) => set({ userRole: role }),

      setCompanyName: (name: string) => set({ companyName: name }),

      setUserName: (name: string) => set({ userName: name }),

      resetDemo: () => set(DEFAULT_STATE),
    }),
    {
      name: 'sam-demo',
    }
  )
);