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

interface TestState {
  // Shell — filled during TOEIC feature implementation
  currentPart: number | null
  answers: Record<string, string>
  setCurrentPart: (part: number | null) => void
  setAnswer: (questionId: string, answer: string) => void
  reset: () => void
}

export const useTestStore = create<TestState>()(
  persist(
    (set) => ({
      currentPart: null,
      answers: {},
      setCurrentPart: (part) => set({ currentPart: part }),
      setAnswer: (questionId, answer) =>
        set((state) => ({
          answers: { ...state.answers, [questionId]: answer },
        })),
      reset: () => set({ currentPart: null, answers: {} }),
    }),
    { name: "test-store" },
  ),
)
