import { create } from "zustand";
import type { ClaimCheck, ExtractionState } from "@/lib/types";
import { DEFAULT_EXTRACTION_STATE } from "@/lib/defaults";

interface ClaimsStore {
  // State
  claims: ClaimCheck[];
  inputText: string;
  extraction: ExtractionState;

  // Actions
  setInputText: (text: string) => void;
  setClaims: (claims: ClaimCheck[]) => void;
  setExtraction: (state: Partial<ExtractionState>) => void;
  clearAll: () => void;
}

export const useClaimsStore = create<ClaimsStore>((set) => ({
  claims: [],
  inputText: "",
  extraction: DEFAULT_EXTRACTION_STATE,

  setInputText: (text) => set({ inputText: text }),
  setClaims: (claims) => set({ claims }),
  setExtraction: (state) =>
    set((prev) => ({
      extraction: { ...prev.extraction, ...state },
    })),
  clearAll: () =>
    set({
      claims: [],
      inputText: "",
      extraction: DEFAULT_EXTRACTION_STATE,
    }),
}));
