import { VideoDriverEnum } from "@/lib/enums/video-driver.enum"
import { IColourRecipe, IPigment } from "@/lib/interfaces/course/course.interface"

export interface LessonStepDto {
  title: string
  text: string
  at_seconds: number | null
}

/** What to play, from the API's video_source (technical-plan 6.5). */
export type VideoSourceDto =
  | {
      type: "hls"
      url: string
      key_auth: boolean
      version?: string
      poster?: string | null
      duration?: number | null
      watermark?: string | null
    }
  | { type: "embed"; html: string }
  | { type: "file"; url: string; poster?: string | null }

export interface LessonDto {
  id: number
  title: string
  description: string | null
  avatar: string | null
  sort_code: number | null
  status: boolean | null
  is_free_preview: boolean
  duration_seconds: number | null
  steps: LessonStepDto[]
  video_driver: VideoDriverEnum | null
  video: string | null
  video_source: VideoSourceDto | null
  course: { id: number; title: string; coach_name: string | null; palette: IPigment[]; recipes: IColourRecipe[] }
  number: number | null
  lessons_count: number | null
  next_lesson: { id: number; title: string; is_free_preview: boolean; duration_seconds: number | null; open: boolean } | null
  progress: { position_seconds: number; done: boolean }
  /** The learner's latest homework for this lesson (not cancelled), or null. */
  homework: {
    id: number
    title: string
    status: "pending" | "reviewed" | "awaiting_payment" | "cancelled"
    status_label: string
    submitted_at: string | null
    reviewed_at: string | null
  } | null
  /** False while a homework waits for the coach: one at a time per lesson. */
  can_send_homework: boolean
}

export type LessonFetchResponseDto = LessonDto