import { PaginationMeta } from './Assessment';

export type CourseStatus = 'draft' | 'published' | 'archived';
export type MaterialContentType = 'text' | 'pdf' | 'video_link' | 'external_link';
export type EnrollmentStatus = 'not_started' | 'in_progress' | 'completed';
export type CourseTargetType = 'all' | 'department' | 'org_unit' | 'position' | 'specific_employees';

export interface Course {
  id: string;
  title: string;
  description: string | null;
  thumbnail_path: string | null;
  target_type: CourseTargetType | null;
  status: CourseStatus;
  estimated_duration_minutes: number | null;
  linked_quiz: { id: string; name: string } | null;
  materials_count: number;
  enrollments_count: number;
  created_at: string;
}

export interface CourseDetail {
  id: string;
  title: string;
  description: string | null;
  thumbnail_path: string | null;
  target_type: CourseTargetType | null;
  target_ids: string[] | null;
  available_from: string | null;
  available_until: string | null;
  is_periodic: boolean;
  recurrence_pattern: Record<string, unknown> | null;
  quiz_required_for_completion: boolean;
  notify_on_publish: boolean;
  status: CourseStatus;
  estimated_duration_minutes: number | null;
  next_course_id: string | null;
  linked_quiz: { id: string; name: string } | null;
  next_course: { id: string; title: string } | null;
  materials: CourseMaterial[];
  enrollment_stats: {
    total: number;
    not_started: number;
    in_progress: number;
    completed: number;
  };
  creator: { id: string; name: string } | null;
  created_at: string;
  updated_at: string;
}

export interface CourseMaterial {
  id: string;
  course_id: string;
  title: string;
  content_type: MaterialContentType;
  rich_content: string | null;
  original_filename: string | null;
  video_url: string | null;
  external_url: string | null;
  display_order: number;
  duration_minutes: number | null;
  download_url: string | null;
  created_at: string;
  is_viewed?: boolean;
}

export interface CourseEnrollment {
  id: string;
  employee: {
    employee_id: string;
    firstname: string;
    lastname: string;
    org_unit: string | null;
    position: string | null;
  };
  enrolled_at: string;
  status: EnrollmentStatus;
  completion_percentage: number;
  completed_at: string | null;
  created_at: string;
}

export interface CreateCoursePayload {
  title: string;
  description?: string | null;
  target_type?: CourseTargetType | null;
  target_ids?: string[] | null;
  available_from?: string | null;
  available_until?: string | null;
  is_periodic?: boolean;
  recurrence_pattern?: Record<string, unknown> | null;
  linked_quiz_id?: string | null;
  quiz_required_for_completion?: boolean;
  notify_on_publish?: boolean;
  estimated_duration_minutes?: number | null;
  next_course_id?: string | null;
}

export interface UpdateCoursePayload extends Partial<CreateCoursePayload> {
  id: string;
}

export interface DeleteCoursePayload {
  message: string;
  id?: string;
}

export interface CreateMaterialPayload {
  courseId: string;
  title: string;
  content_type: MaterialContentType;
  rich_content?: string;
  file?: File;
  video_url?: string;
  external_url?: string;
  duration_minutes?: number;
}

export interface UpdateMaterialPayload {
  courseId: string;
  materialId: string;
  title?: string;
  content_type?: MaterialContentType;
  rich_content?: string;
  file?: File;
  video_url?: string;
  external_url?: string;
  duration_minutes?: number;
}

export interface MyCourse {
  id: string;
  course: {
    id: string;
    title: string;
    description: string | null;
    thumbnail_path: string | null;
    estimated_duration_minutes: number | null;
    materials_count: number;
  };
  enrolled_at: string;
  status: EnrollmentStatus;
  completion_percentage: number;
  completed_at: string | null;
}

export interface MyCourseDetail {
  course: {
    id: string;
    title: string;
    description: string | null;
    estimated_duration_minutes: number | null;
    linked_quiz_id: string | null;
    quiz_required_for_completion: boolean;
  };
  enrollment: {
    id: string;
    status: EnrollmentStatus;
    completion_percentage: number;
    enrolled_at: string;
    completed_at: string | null;
  };
  materials: CourseMaterial[];
}

export interface CompletionReport {
  stats: {
    total: number;
    completed: number;
    in_progress: number;
    not_started: number;
    completion_rate: number;
  };
  completed: CourseEnrollment[];
  in_progress: CourseEnrollment[];
  not_started: CourseEnrollment[];
}

export interface LmsDashboardData {
  summary: {
    total_courses: number;
    published_courses: number;
    total_enrollments: number;
    total_completions: number;
    avg_completion_rate: number;
    total_materials: number;
  };
  monthly_trend: { label: string; enrollments: number; completions: number }[];
  top_courses: { id: string; title: string; enrollments: number; completion_rate: number }[];
  material_type_distribution: { type: string; count: number }[];
}
