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

export const apiGetAdminTerms = (params) => http.get(endpoints.getTermsList, { params })

export const apiShowAdminTerm = (id) => http.get(buildUrl(endpoints.showTerm, { id }))

export const apiAddAdminTerm = (payload) => http.post(endpoints.addNewTerm, payload)

export const apiUpdateAdminTerm = (id, payload) =>
  http.patch(buildUrl(endpoints.updateTerm, { id }), payload)

export const apiDeleteAdminTerm = (id) => http.delete(buildUrl(endpoints.deleteTerm, { id }))

export const apiCloneAdminTerm = (id) => http.post(buildUrl(endpoints.cloneTerm, { id }))

export const apiGetAdminTermStudents = (termId, params) =>
  http.get(buildUrl(endpoints.listUserTerm, { termId }), { params })

export const apiGetAdminTermEnrollees = (termId, params) =>
  http.get(buildUrl(endpoints.getTermEnrollees, { termId }), { params })

export const apiAddAdminTermStudents = (termId, payload) =>
  http.post(buildUrl(endpoints.addUserTerm, { termId }), payload)

export const apiRemoveAdminTermStudent = (termId, userId) =>
  http.delete(buildUrl(endpoints.removeUserTerm, { termId, userId }))

export const apiToggleAdminTermStudentLeave = (termId, userId, payload) =>
  http.post(buildUrl(endpoints.changeLeaveStatus, { termId, userId }), payload)

export const apiGetAdminTermCourses = (termId, params) =>
  http.get(buildUrl(endpoints.listCourseTerm, { termId }), { params })

export const apiAddAdminTermCourses = (termId, payload) =>
  http.post(buildUrl(endpoints.addCourseTerm, { termId }), payload)

export const apiRemoveAdminTermCourse = (termId, courseId) =>
  http.delete(buildUrl(endpoints.removeCourseTerm, { termId, courseId }))
