import axiosInstance from "@/apis/axios.config";
import type {AssignmentQuery} from "@/types/query";
import type {AssignmentDTO} from "@/types/dto";

const ASSIGNMENT_PREFIX = "/api/assignment"

const assignmentApis = {
    getAssignmentById(assignmentId: number) {
        return axiosInstance.get(`${ASSIGNMENT_PREFIX}/byAssignment/${assignmentId}`)
    },
    getAssignmentByQuery(query:AssignmentQuery, page: number=0, size: number=10){
        return axiosInstance.post(`${ASSIGNMENT_PREFIX}/query`, {
            ...query
        }, {
            params: {
                page,
                size
            }
        })
    },
    createAssignment(courseId:number, assignmentDTO: AssignmentDTO){
        return axiosInstance.post(`${ASSIGNMENT_PREFIX}`, assignmentDTO, {
            params: {
                courseId
            }
        });
    },
    getAssignmentByCourseId(courseId:number, page: number=0, size: number=10){
        return axiosInstance.get(`${ASSIGNMENT_PREFIX}/byCourse/${courseId}`, {
            params: {
                page,
                size
            }
        })
    },
    // 新增：获取学生在特定课程下的作业状态
    getStudentAssignmentsByCourse(studentId: string, courseId: string) {
        return axiosInstance.get("/api/course/student/assignments", {
            params: {
                studentId,
                courseId
            }
        })
    },
    updateAssignment(assignmentId:number, assignmentDTO:AssignmentDTO){
        return axiosInstance.post(`${ASSIGNMENT_PREFIX}/update`, assignmentDTO, {
            params: {
                assignmentId
            }
        })
    },
    deleteAssignmentById(teacherId:number, assignmentId:number){
        return axiosInstance.delete(`${ASSIGNMENT_PREFIX}`, {
            params: {
                teacherId,
                assignmentId
            }
        })
    },
    // 新增：查询某班级某作业的情况
    getAssignmentStatusByClass: (classId: string, assignmentId: string) => {
        return axiosInstance.get(`${ASSIGNMENT_PREFIX}/class/${classId}/status`, {
            params: {
                assignmentId
            }
        })
    }

}

export default assignmentApis
