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

export const apiGetAdminAssignments = (params) => http.get(endpoints.getAssignmentsList, { params })

export const apiShowAdminAssignment = (id) => http.get(buildUrl(endpoints.showAssignment, { id }))

export const apiAddAdminAssignment = (payload) => http.post(endpoints.addNewAssignment, payload)

// Backend uses PATCH /homeworks/:id (not PUT).
export const apiUpdateAdminAssignment = (id, payload) =>
  http.patch(buildUrl(endpoints.updateAssignment, { id }), payload)

export const apiDeleteAdminAssignment = (id) =>
  http.delete(buildUrl(endpoints.deleteAssignment, { id }))

export const apiGetAdminAssignmentSubmissions = (homeworkId, params) =>
  http.get(buildUrl(endpoints.getAssignmentSubmissions, { homeworkId }), { params })

// Backend exposes submissions flat under /homework-submissions/:submissionId —
// the parent `homeworkId` is not part of the URL, so we ignore it here.
export const apiShowAdminAssignmentSubmission = (_homeworkId, submissionId) =>
  http.get(buildUrl(endpoints.showAssignmentSubmission, { submissionId }))

export const apiReviewAdminAssignmentSubmission = (_homeworkId, submissionId, payload) =>
  http.patch(buildUrl(endpoints.reviewAssignmentSubmission, { submissionId }), payload)
