/**
 * AI-generated course plan — types mirror the backend controller's
 * response shape in `encoach_ai_course.controllers.course_plan`.
 */

export type CoursePlanSkill =
  | "reading"
  | "writing"
  | "listening"
  | "speaking"
  | "grammar"
  | "vocabulary"
  | "integrated";

export type CoursePlanMaterialType =
  | "reading_text"
  | "listening_script"
  | "speaking_prompt"
  | "writing_prompt"
  | "grammar_lesson"
  | "vocabulary_list"
  | "practice"
  | "other";

export interface CoursePlanOutcome {
  code: string;
  description: string;
}

export interface CoursePlanGrammarItem {
  code: string;
  label: string;
  sub_items?: string[];
}

export interface CoursePlanAssessmentComponent {
  name: string;
  weight: number;
}

export interface CoursePlanAssessment {
  continuous_assessment?: {
    total_weight?: number;
    components?: CoursePlanAssessmentComponent[];
  };
  final_exam?: {
    total_weight?: number;
  };
}

export interface CoursePlanResource {
  type: string;
  citation: string;
}

export interface CoursePlanWeekItem {
  skill: CoursePlanSkill | string;
  outcome_codes: string[];
  remarks?: string;
}

export interface CoursePlanWeek {
  id: number;
  week_number: number;
  date_label: string;
  unit: string;
  focus: string;
  items: CoursePlanWeekItem[];
  material_count: number;
}

export interface CoursePlanMaterial {
  id: number;
  plan_id: number;
  week_id: number | null;
  week_number: number;
  skill: string;
  material_type: CoursePlanMaterialType | string;
  title: string;
  summary: string;
  /** Loose shape: depends on material_type. */
  body: Record<string, unknown>;
  body_text: string;
}

export interface CoursePlan {
  id: number;
  name: string;
  course_id: number | null;
  course_name: string;
  cefr_level: string;
  total_weeks: number;
  contact_hours_per_week: number;
  skills_division: string;
  description: string;
  status: "draft" | "generated" | "approved" | "archived";
  objectives: string[];
  outcomes: Partial<Record<CoursePlanSkill, CoursePlanOutcome[]>>;
  grammar: CoursePlanGrammarItem[];
  assessment: CoursePlanAssessment;
  resources: CoursePlanResource[];
  week_count: number;
  material_count: number;
  created_at: string | null;
  weeks?: CoursePlanWeek[];
  materials?: CoursePlanMaterial[];
}

export interface CoursePlanGenerateBrief {
  title: string;
  cefr_level?: string;
  total_weeks?: number;
  contact_hours_per_week?: number;
  skills_division?: string;
  grammar_focus?: string[];
  resources?: string[];
  learner_profile?: string;
  notes?: string;
  course_id?: number;
}
