import type { LocalePair } from '../../certification/types/certification';

export type QuestionForm = 'ESSAY' | 'CHOICE';

export interface EstimatedTime {
  days: number;
  hours: number;
  minutes: number;
}

/** Question bank quality control (US-EXAM-003). */
export type QuestionStatus =
  | 'DRAFT'
  | 'PENDING_APPROVAL'
  | 'APPROVED'
  | 'REJECTED'
  | 'RETIRED';

/**
 * A CHOICE option, as returned by the authoring/QC endpoints. Never carries
 * a correctness flag — the API's own answer-key table is never joined into
 * this response either, so there's nothing to accidentally serialize here.
 */
export interface QuestionOption {
  id: string;
  text: LocalePair;
  order: number;
}

export interface Question {
  id: string;
  certificationId: string;
  certification?: { id: string; name: LocalePair };
  title: LocalePair;
  description: LocalePair;
  form: QuestionForm;
  time: EstimatedTime | null;
  points: number;
  isActive: boolean;
  status: QuestionStatus;
  reviewRemark: string | null;
  reviewedAt: string | null;
  submittedAt: string | null;
  createdAt: string;
  updatedAt: string;
  /** Only populated when explicitly requested (`?i=options`). */
  options?: QuestionOption[];
}

export interface ReviewQuestionPayload {
  id: string;
  outcome: 'APPROVED' | 'REJECTED' | 'RETIRED';
  remark?: string;
}

export interface ListResponse<T> {
  total: number;
  items: T[];
}

export interface CreateQuestionPayload {
  certificationId: string;
  title: LocalePair;
  description?: LocalePair;
  form: QuestionForm;
  time?: EstimatedTime;
  points: number;
}

export interface UpdateQuestionPayload {
  id: string;
  certificationId?: string;
  title?: LocalePair;
  description?: LocalePair;
  form?: QuestionForm;
  time?: EstimatedTime;
  points?: number;
  isActive?: boolean;
}

export interface QuestionOptionInput {
  text: LocalePair;
  isCorrect: boolean;
}

export interface SetQuestionOptionsPayload {
  id: string;
  options: QuestionOptionInput[];
}
