export type CbtMode = 'sequential' | 'random' | 'wrong-only' | 'bookmarks-only';

export type ExamCategory = {
  id: string;
  label: string;
};

export type Subject = {
  id: string;
  examId: string;
  label: string;
};

export type QuestionSet = {
  id: string;
  examId: string;
  subjectId: string;
  label: string;
  sourceLabel: string;
};

export type QuestionChoice = {
  value: string;
  label: string;
};

export type QuestionRecord = {
  id: string;
  examId: string;
  subjectId: string;
  setId: string;
  type: 'multiple-choice';
  body: string;
  answerValue: string;
  explanation: string;
  difficulty: 'easy' | 'medium' | 'hard';
  sourceLabel: string;
  tags: string[];
  correctRate: number;
  choices: QuestionChoice[];
  isActive: boolean;
};

export type SessionAnswer = {
  questionId: string;
  selectedValue: string | null;
  isCorrect?: boolean;
  isMarked: boolean;
  isBookmarked: boolean;
  answeredAt: string | null;
};

export type CbtSessionRecord = {
  id: string;
  examId: string;
  subjectIds: string[];
  questionSetId: string | null;
  mode: CbtMode;
  questionIds: string[];
  questionCount: number;
  startedAt: string;
  submittedAt: string | null;
  score: number | null;
  correctCount: number;
  wrongCount: number;
  currentQuestionIndex: number;
  revealedExplanationQuestionIds: string[];
  answers: SessionAnswer[];
};

export type WrongNoteItem = {
  questionId: string;
  createdAt: string;
  subjectId: string;
  examId: string;
  wrongCount: number;
  lastSessionId: string;
};

export type BookmarkItem = {
  questionId: string;
  createdAt: string;
  updatedAt: string;
};

export type ProgressStat = {
  subjectId: string;
  solvedCount: number;
  correctCount: number;
  wrongCount: number;
  accuracyRate: number;
};

export type CbtStorageState = {
  sessions: CbtSessionRecord[];
  wrongNotes: WrongNoteItem[];
  bookmarks: BookmarkItem[];
  progressStats: ProgressStat[];
  activeSessionId: string | null;
};
