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

interface AppState {
  apiKey: string
  setApiKey: (key: string) => void
  clearApiKey: () => void

  // SR-002 (CR-20260607-001 rev.2): in desktop mode the user must
  // acknowledge, at least once, that selecting a cloud model sends
  // query + retrieved snippets + the agent prompt to that provider.
  // Persisted so we don't nag on every chat.
  cloudPrivacyAck: boolean
  ackCloudPrivacy: () => void
  resetCloudPrivacy: () => void
}

export const useAppStore = create<AppState>()(
  persist(
    set => ({
      apiKey: '',
      setApiKey: key => set({ apiKey: key }),
      clearApiKey: () => set({ apiKey: '' }),

      cloudPrivacyAck: false,
      ackCloudPrivacy: () => set({ cloudPrivacyAck: true }),
      resetCloudPrivacy: () => set({ cloudPrivacyAck: false }),
    }),
    { name: 'lambdagent-store' },
  ),
)
