export type ExamModule = "reading" | "listening" | "writing" | "speaking" | "level";

export type ExamAccess = "public" | "private" | "confidential";

export interface Exam {
  id: number;
  title: string;
  module: ExamModule;
  subject_id?: number;
  topic_ids?: number[];
  created_by: string;
  rubric_ids: number[];
  difficulty: string;
  exercises_count: number;
  timer: number;
  access: ExamAccess;
  created_at: string;
  is_diagnostic?: boolean;
}

export interface Rubric {
  id: number;
  name: string;
  description: string;
  module: ExamModule;
  criteria: RubricCriterion[];
}

export interface RubricCriterion {
  id: number;
  name: string;
  description: string;
  max_score: number;
}

export interface RubricGroup {
  id: number;
  name: string;
  rubric_ids: number[];
  rubric_names?: string[];
  created?: string;
}

export interface ExamStructure {
  id: number;
  name: string;
  entity_id: number;
  entity_name: string;
  industry: string;
  modules: ExamModule[];
  config: ExamStructureConfig;
  created_at: string;
}

export interface ListeningPartConfig {
  key: string;
  label: string;
  questions: number;
  question_types: Record<string, number>;
}

export interface ReadingPassageConfig {
  style: string;
  questions: number;
  question_types: Record<string, number>;
}

export interface SpeakingPartConfig {
  key: string;
  label: string;
  duration_min: number;
  duration_max: number;
}

export interface WritingTaskConfig {
  type: string;
  min_words: number;
  label?: string;
}

export interface LevelExerciseEntry {
  type: string;
  quantity: number;
}

export interface IndustryExerciseEntry {
  type: string;
  quantity: number;
}

export interface ExamStructureConfig {
  exam_type: "academic" | "general";
  listening?: {
    parts: ListeningPartConfig[];
    total_questions: number;
  };
  reading?: {
    passages: ReadingPassageConfig[];
    total_questions: number;
  };
  writing?: {
    tasks: WritingTaskConfig[];
    /** @deprecated kept for backward compat reads */
    task1?: { type: string; min_words: number };
    /** @deprecated kept for backward compat reads */
    task2?: { type: string; min_words: number };
    rubric_id: number | null;
  };
  speaking?: {
    parts: SpeakingPartConfig[];
    rubric_id: number | null;
  };
  level?: {
    exercise_types: Record<string, number>;
    entries?: LevelExerciseEntry[];
  };
  industry?: {
    exercise_types: Record<string, number>;
    entries?: IndustryExerciseEntry[];
    difficulty: string;
  };
}
