import { http } from '@/services/api/http'
import { buildUrl, endpoints } from '@/services/api/endpoints'

export const apiGetStudentExams = (params) => http.get(endpoints.getStudentExamsList, { params })

export const apiShowStudentExam = (id) => http.get(buildUrl(endpoints.showExam, { id }))

// POST /exams/:examId/start — begins (or resumes) an attempt; returns the
// attempt with startedAt + deadlineAt. Idempotent on the backend.
export const apiStartStudentExam = (id) => http.post(buildUrl(endpoints.startExam, { examId: id }))

export const apiSubmitStudentExamAttempt = (id, payload) =>
  http.post(buildUrl(endpoints.submitExam, { examId: id }), payload)

// GET /student/exam-results — paginated attempts across the student's exams.
export const apiGetStudentExamResults = (params) =>
  http.get(endpoints.getStudentExamResults, { params })
