import { api } from "@/lib/api-client";
import type { ExamSession, ExamAutoSave, ExamSubmitResponse } from "@/types";
import type { ApiSuccessResponse } from "@/types";

export const examSessionService = {
  getSession: (examId: number) =>
    api.get<ExamSession>(`/exam/${examId}/session`),

  autoSave: (examId: number, data: ExamAutoSave) =>
    api.post<ApiSuccessResponse>(`/exam/${examId}/autosave`, data),

  submit: (examId: number, data?: { attempt_id: number; answers: { question_id: number; answer: unknown }[] }) =>
    api.post<ExamSubmitResponse>(`/exam/${examId}/submit`, data),

  getStatus: (examId: number) =>
    api.get<{ status: string; scores_available: boolean }>(`/exam/${examId}/status`),

  getResults: (examId: number) =>
    api.get(`/exam/${examId}/results`),
};
