import type { Bilingual } from '@ema-platform/api';

export type AttemptStatus = 'IN_PROGRESS' | 'SUBMITTED' | 'EXPIRED';
export type QuestionForm = 'ESSAY' | 'CHOICE';

export interface CandidateOption {
  id: string;
  text: Bilingual;
  order: number;
}

/** Never carries a correct-answer flag — the API doesn't send one. */
export interface CandidateQuestion {
  id: string;
  title: Bilingual;
  form: QuestionForm;
  points: number;
  options: CandidateOption[];
}

export interface ExamAttempt {
  id: string;
  examId: string;
  registrationId: string;
  status: AttemptStatus;
  startedAt: string;
  expiresAt: string;
  submittedAt: string | null;
}

export interface CandidateAnswer {
  id: string;
  attemptId: string;
  questionId: string;
  selectedOptionId: string | null;
  answerText: string | null;
}

/** Response shape shared by POST /exam-attempts/start and GET .../mine/:examId. */
export interface AttemptSession {
  attempt: ExamAttempt;
  questions: CandidateQuestion[];
  answers: CandidateAnswer[];
  serverTime: string;
  remainingSeconds: number;
}

export type SaveState = 'idle' | 'saving' | 'saved' | 'error';

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

/**
 * The subset of `GET /exams/registrations/mine`'s response this feature
 * reads — the endpoint returns the full raw exam/registration, this is
 * just this feature's own narrow view of it (matches the sibling `exams`
 * feature's pattern of each screen typing only what it uses).
 */
export interface RegistrationWithExam {
  id: string;
  admissionNumber: string;
  kind: 'NEW' | 'RETAKE';
  attemptNumber: number;
  attendanceStatus: string;
  exam?: {
    id: string;
    title: Bilingual;
    direction?: Bilingual;
    date: string;
    venue: string | null;
    status: string;
    givenTime: EstimatedTime | null;
    certification?: { name?: Bilingual };
  };
}
