import type { Topic } from "./sheet";

export type Lesson = {
  id: string;
  title: string;
  thumbnail_url: string;
  topic: Topic;
};

export interface LessonsResponse {
  data: Lesson[];
  pagination: {
    page: number;
    limit: number;
    total: number;
    total_pages: number;
  };
}

export interface LessonDetails {
  title: string;
  topic_id: string;
  video_url: string;
  content: string;
  description: string;
  thumbnail_url: string;
  resources: any[];
  id: string;
  created_by: {
    id: string;
    name: string;
    email: string;
  };
  topic: Topic[];
}

export interface CircleState {
  h: number;
  k: number;
  r: number;
}

export interface Point {
  x: number;
  y: number;
}

export type QuizOption = {
  id: string;
  text: string;
  isCorrect: boolean;
  feedback: string;
};

export interface QuizData {
  id: number;
  question: string;
  options: QuizOption[];
  explanation: string;
}

export interface LessonMetadata {
  id: string;
  title: string;
  description: string;
  iconName:
    | "Circle"
    | "Triangle"
    | "Square"
    | "Chart"
    | "Target"
    | "Calculator"
    | "TrendingUp"
    | "Percent"
    | "Scale"
    | "BarChart3"
    | "Layers"
    | "Grid"
    | "BookOpen"
    | "PieChart";
  color: string;
  category: string;
}

// ── Practice Mode Types ──

export type Difficulty = "easy" | "medium" | "hard";
export type PracticeQuestionType = "mcq" | "spr";
export type PracticeSection = "math" | "rw";
export type PracticeView = "lobby" | "session" | "results" | "treasure";

export interface PracticeChoice {
  label: string; // "A" | "B" | "C" | "D"
  text: string; // HTML-safe answer text
}

export interface PracticeQuestion {
  id: string;
  type: PracticeQuestionType;
  questionHtml: string;
  passage?: string;
  choices: PracticeChoice[];
  correctAnswer: string;
  explanation: string;
  hasFigure: boolean;
  figureDescription?: string;
  figureUrl?: string;
}

export interface PracticeTopic {
  id: string;
  name: string;
  section: PracticeSection;
  category: string;
  color: string;
  questions: {
    easy: PracticeQuestion[];
    medium: PracticeQuestion[];
    hard: PracticeQuestion[];
  };
}

export type TopicRegistry = Record<string, PracticeTopic>;

export interface AnswerRecord {
  selectedAnswer: string | null;
  isCorrect: boolean | null;
  isSubmitted: boolean;
  coinAwarded: boolean;
}

export interface PracticeSessionState {
  topicId: string;
  topicName: string;
  difficulty: Difficulty;
  questions: PracticeQuestion[];
  currentIndex: number;
  answers: Record<string, AnswerRecord>;
  coinsEarnedThisSession: number;
}

export interface TopicDifficultyProgress {
  attempted: number;
  correct: number;
}

export interface GoldCoinState {
  totalCoins: number;
  earnedQuestions: Record<string, boolean>;
  topicProgress: Record<
    string,
    {
      easy: TopicDifficultyProgress;
      medium: TopicDifficultyProgress;
      hard: TopicDifficultyProgress;
    }
  >;
}

export const COIN_REWARDS: Record<Difficulty, number> = {
  easy: 5,
  medium: 10,
  hard: 15,
};
