import axiosInstance from "@/apis/axios.config";
import type {CourseQuery} from "@/types/query";
import type {AssignmentQueryDTO, CourseDTO, CourseUpdateDTO, EnrollDTO} from "@/types/dto";

const COURSE_PREFIX = "/api/course"
const ASSIGNMENT_PREFIX = "/api/assignment"

const courseApis = {
    createCourse(courseDTO: CourseDTO){
      return axiosInstance.post(`${COURSE_PREFIX}`, courseDTO)
    },
    deleteCourse: (courseId:number) => {
        return axiosInstance.delete(`${COURSE_PREFIX}/deleteCourse`, {
            params: {
                courseId
            }
        })
    },
    getCourseByStudentId(page: number=0, size: number=10){
        return axiosInstance.get(`${COURSE_PREFIX}/byStudent`, {
            params: {
                page,
                size
            }
        })
    },
    getCourseByTeacherId(page: number=0, size: number=10){
        return axiosInstance.get(`${COURSE_PREFIX}/byTeacher`, {
            params: {
                page,
                size
            }
        })
    },
    getCourseByCourseId(courseId: number, page: number=0, size: number=10){
        return axiosInstance.get(`${COURSE_PREFIX}/${courseId}`, {
            params: {
                page,
                size
            }
        })
    },
    getAllCourse(courseQuery: CourseQuery, page: number=0, size: number=10){
        return axiosInstance.post(`${COURSE_PREFIX}/query`,courseQuery, {
            params: {
                page,
                size
            }
        })
    },
    enrollCourse(enrollDTO: EnrollDTO){
        return axiosInstance.post(`${COURSE_PREFIX}/enroll`, enrollDTO)
    },
    updateCourse(courseId: number, courseUpdateDTO:CourseUpdateDTO){
        return axiosInstance.put(`${COURSE_PREFIX}`, courseUpdateDTO, {
            params: {
                courseId
            }
        })
    },
    findAssignmentPage: (assignmentQueryDTO: AssignmentQueryDTO, page: number=0, size: number=10) => {
        return axiosInstance.post(`${ASSIGNMENT_PREFIX}/query`, assignmentQueryDTO, {
            params: {
                page,
                size
            }
        });
    }
    ,
    // getEnrollCode: (userId:number, courseId:number) => {
    //     return axiosInstance.get(`${COURSE_PREFIX}/getEnrollCode`, {
    //         params: {
    //             userId: userId,
    //             courseId: courseId
    //         }
    //     })
    // },
    dropCourse: (courseId:number) => {
        return axiosInstance.delete(`${COURSE_PREFIX}/dropCourse`, {
            params: {
                courseId
            }
        })
    },
    // 新增：查询某课程的所有班级
    getClassesByCourse: (courseId: number) => {
        return axiosInstance.get(`/api/class/select`, {
            params: {
                courseId
            }
        })
    },
}

export default courseApis