import type { UiTrainingType } from '../constants/training-record-options';

export interface TrainingRecord {
  id: number;
  organization_id: string;
  user_id: string | null;
  employee_id: number | null;
  employee_code: string | null;
  user_name: string;
  company_name: string | null;
  department_name: string | null;
  course_id: number | null;
  course_name: string;
  training_date: string;
  training_type: UiTrainingType;
  submitted_minutes: number | null;
  hours: number;
  approved_minutes: number | null;
  approved_hours: number | null;
  category: 'K' | 'S' | 'A' | null;
  organizer: string | null;
  note: string | null;
  certificate_preview_url: string | null;
  certificate_preview_type: string | null;
  approval_status: 'draft' | 'pending' | 'approved' | 'rejected' | 'needs_revision';
  reviewer_note: string | null;
  reject_reason: string | null;
  reviewed_by: string | null;
  reviewed_at: string | null;
  created_by: string;
  created_by_name: string | null;
  created_at: string;
  updated_at: string;
}

export interface Certificate {
  id: number;
  organization_id: string;
  training_record_id: number;
  file_name: string;
  file_type: string;
  file_size: number;
  storage_key: string;
  file_url: string | null;
  uploaded_by: string;
  uploaded_at: string;
  created_at: string;
  updated_at: string;
}

export interface TrainingRecordFilters {
  page?: number;
  limit?: number;
  search?: string;
  statuses?: string;
  types?: string;
  year?: string;
  company?: string;
  department?: string;
  sort?: string;
}

export interface TrainingRecordsResponse {
  success: boolean;
  time: string;
  message: string;
  total_training_records: number;
  offset: number;
  limit: number;
  training_records: TrainingRecord[];
}

export interface TrainingRecordByIdResponse {
  success: boolean;
  time: string;
  message: string;
  training_record: TrainingRecord;
}

export interface CertificatesResponse {
  success: boolean;
  time: string;
  message: string;
  certificates: Certificate[];
}

export interface TrainingRecordMutationPayload {
  employeeId: number;
  courseId?: number | null;
  courseName: string;
  trainingDate: string;
  trainingType: TrainingRecord['training_type'];
  submittedMinutes: number;
  hours?: number;
  organizer?: string;
  note?: string;
  submissionMode?: 'draft' | 'submit';
}

export interface TrainingRecordCourseOption {
  id: number;
  course_code: string | null;
  name: string;
  category: string;
  standard_hours: number;
  organizer: string | null;
  certificate_required: boolean;
}

export interface TrainingRecordReviewPayload {
  status: 'approved' | 'needs_revision';
  category?: 'K' | 'S' | 'A';
  approvedMinutes?: number;
  approvedHours?: number;
  reviewerNote?: string;
  rejectReason?: string;
}

export interface TrainingRecordFormOption {
  value: string;
  label: string;
}

export interface TrainingRecordImportSummary {
  total_rows: number;
  imported_records: number;
  failed_rows: number;
}

export interface TrainingRecordImportError {
  row: number;
  employee_code?: string;
  message: string;
}

export interface TrainingRecordImportResponse {
  success: boolean;
  message: string;
  import_job_id?: number;
  summary: TrainingRecordImportSummary;
  errors: TrainingRecordImportError[];
}
