import { api } from "@/lib/api-client";
import type {
  IELTSExamConfig,
  IELTSExamResponse,
  IELTSSkillConfig,
  ContentPoolItem,
  ContentPoolFilters,
  AssemblyResult,
  ExamValidationReport,
  ExamAssignRequest,
} from "@/types";
import type { ApiSuccessResponse } from "@/types";

export const ieltsExamService = {
  create: (data: IELTSExamConfig) =>
    api.post<IELTSExamResponse>("/exam/ielts/create", data),

  getSkills: (examId: number) =>
    api.get<IELTSSkillConfig[]>(`/exam/ielts/${examId}/skills`),

  getContentPoolCount: (examId: number) =>
    api.get<Record<string, number>>(`/exam/ielts/${examId}/content-pool-count`),

  getContentPool: (examId: number, filters: ContentPoolFilters) =>
    api.get<ContentPoolItem[]>(`/exam/ielts/${examId}/content-pool`, filters as Record<string, string | number | boolean | undefined>),

  autoAssemble: (examId: number) =>
    api.post<AssemblyResult[]>(`/exam/ielts/${examId}/auto-assemble`),

  suggest: (examId: number) =>
    api.post<AssemblyResult[]>(`/exam/ielts/${examId}/suggest`),

  saveQuestions: (examId: number, sectionId: number, questionIds: number[]) =>
    api.put<ApiSuccessResponse>(`/exam/ielts/${examId}/sections/${sectionId}/questions`, { question_ids: questionIds }),

  validate: (examId: number) =>
    api.get<ExamValidationReport>(`/exam/ielts/${examId}/validate`),

  update: (examId: number, data: { status: string }) =>
    api.put<ApiSuccessResponse>(`/exam/ielts/${examId}`, data),

  assign: (examId: number, data: ExamAssignRequest) =>
    api.post<ApiSuccessResponse>(`/exam/ielts/${examId}/assign`, data),
};
