import {axios} from "@/requests/axios.config";
import courseSelectionAPIs from "@/api/course/courseSelection";

const prefix = "/course";

function createCourse(data) {
  return axios.post(`${prefix}/create`, data);
}

function getAllCourses() {
  return axios.get(`${prefix}/all`);
}

function getAllCoderCourses() {
  return axios.get(`${prefix}/coder_all`);
}

function getExampleCourses() {
  return axios.get(`${prefix}/example`);
}

function getTeacherCourses() {
  return axios.get(`${prefix}/teacher`);
}

function getStudentCourses() {
  return axios.get(`${prefix}/student`);
}

function getCourseById(id) {
  return axios.get(`${prefix}/getCourseById`, {
    params: {
      id
    },
  });
}

function updateCourse(data) {
  return axios.put(`${prefix}/update`, data);
}

function deleteCourse(courseId) {
  return axios.delete(`${prefix}/delete`, {
    params: {
      courseId,
    }
  });
}

function getCourseByCoderId(coderId) {
  return axios.get(`${prefix}/getCourseByCoderId`, {
    params: {
      coderId,
    }
  });
}

function getCourseByEvalId(evalId) {
  return axios.get(`${prefix}/getCourseByEvalId`, {
    params: {
      evalId,
    }
  });
}

function checkCourseNameUnique(id, name) {
  return axios.get(`${prefix}/checkName`, {
    params: {id, name}
  });
}

function checkCourseCodeUnique(id, code) {
  return axios.get(`${prefix}/checkCode`, {
    params: {id, code}
  });
}

function uploadCourseImage(name, image) {
  let data = new FormData();
  data.append("name", name);
  data.append("file", image);
  return axios.post(`${prefix}/uploadImage`, data, {
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
}

const courseAPIs = {
  createCourse,
  getAllCourses,
  getAllCoderCourses,
  getTeacherCourses,
  getStudentCourses,
  getCourseById,
  deleteCourse,
  updateCourse,
  getExampleCourses,
  ...courseSelectionAPIs,
  getCourseByCoderId,
  checkCourseNameUnique,
  checkCourseCodeUnique,
  getCourseByEvalId,
  uploadCourseImage,
};

export default courseAPIs;
