import { api } from "@/lib/api-client"; import type { Proficiency, ProficiencySummary, LearningPlan, DiagnosticSession, DiagnosticQuestion, DiagnosticAnswer, DiagnosticResult, TopicContent, ApiSuccessResponse, } from "@/types"; export const adaptiveService = { async startDiagnostic(subjectId: number): Promise<{ session: DiagnosticSession; first_question: DiagnosticQuestion }> { return api.post("/diagnostic/start", { subject_id: subjectId }); }, async answerDiagnostic(data: DiagnosticAnswer): Promise<{ next_question?: DiagnosticQuestion; completed: boolean }> { return api.post("/diagnostic/answer", data); }, async getDiagnosticResult(sessionId: number): Promise { return api.get(`/diagnostic/${sessionId}/result`); }, async getProficiency(params: { subject_id?: number }): Promise { const raw = await api.get<{ data: Proficiency[] } | Proficiency[]>("/proficiency", params as Record); return Array.isArray(raw) ? raw : (raw as { data: Proficiency[] }).data ?? []; }, async getProficiencySummary(): Promise { const raw = await api.get<{ data: ProficiencySummary[] } | ProficiencySummary[]>("/proficiency/summary"); return Array.isArray(raw) ? raw : (raw as { data: ProficiencySummary[] }).data ?? []; }, async getClassProficiency(params?: { subject_id?: number }): Promise { return api.get("/proficiency/class", params as Record); }, async getLearningPlan(params: { subject_id?: number }): Promise { return api.get("/learning-plan", params as Record); }, async generateLearningPlan(data: { subject_id: number; target_completion?: string }): Promise { return api.post("/learning-plan/generate", data); }, async updateLearningPlan(id: number, data: Partial): Promise { return api.patch(`/learning-plan/${id}`, data); }, async pauseLearningPlan(id: number): Promise { return api.post(`/learning-plan/${id}/pause`); }, async resumeLearningPlan(id: number): Promise { return api.post(`/learning-plan/${id}/resume`); }, async getTopicContent(topicId: number): Promise { return api.get(`/topics/${topicId}/content`); }, async generateTopicContent(topicId: number): Promise { return api.post(`/topics/${topicId}/generate-content`); }, async getPracticeQuestions(topicId: number): Promise<{ questions: unknown[] }> { return api.post(`/topics/${topicId}/practice`); }, async gradePractice(topicId: number, answers: unknown[]): Promise<{ results: unknown[]; mastery_update: number }> { return api.post(`/topics/${topicId}/practice/grade`, { answers }); }, async startMasteryQuiz(topicId: number): Promise<{ questions: unknown[] }> { return api.post(`/topics/${topicId}/mastery-quiz`); }, async submitMasteryQuiz(topicId: number, answers: unknown[]): Promise<{ passed: boolean; score: number; mastery_update: number }> { return api.post(`/topics/${topicId}/mastery-quiz/submit`, { answers }); }, };