import httpClient from '@/utils/http';

import {
  ControllerResponse,
  ExamBatchDeleteRequest,
  ExamBatchExcludeStudentsRequest,
  ExamBatchExcludeStudentsResponse,
  ExamBatchUpdateExamNumberResponse,
  ExamCreateExamStudentRequest,
  ExamDeleteExamStudentBySubjectRequest,
  ExamExamStudentListResponse,
  ExamExamStudentResponse,
  ExamGetExamSubjectsByExamIDResponse,
  ExamSyncExamStudentsRequest,
  ExamSyncExamStudentsResponse,
  ExamUpdateExamStudentRequest,
  ExamUploadExcelResponse
} from './data-contracts';
export default {
  /**
   * @description 创建新的考试学生记录
   */
  examStudentsCreate: (request: ExamCreateExamStudentRequest) => {
    return httpClient.post<
      ControllerResponse & {
        /** 考试学生关联信息响应 */
        data?: ExamExamStudentResponse;
      }
    >(`/exam-students`, { params: request });
  },
  /**
   * @description 根据查询条件获取考试学生列表，支持分页和多种筛选条件
   */
  examStudentsList: (query: {
    /**
     * 页码，默认1
     * @min 1
     */
    page?: number;
    /**
     * 每页数量，默认10，最大100
     * @min 1
     * @max 100
     */
    page_size?: number;
    /** 考试ID */
    exam_id?: number;
    /** 学校ID */
    school_id?: number;
    /** 科目ID */
    subject?: number;
    /**
     * 关键字
     * @maxLength 50
     */
    keyword?: string;
  }) => {
    return httpClient.get<
      ControllerResponse & {
        /** 考试学生关联列表响应结构 */
        data?: ExamExamStudentListResponse;
      }
    >(`/exam-students`, { query: query });
  },
  /**
   * @description 根据ID列表批量删除考试学生记录
   */
  batchDeleteCreate: (request: ExamBatchDeleteRequest) => {
    return httpClient.post<
      ControllerResponse & {
        message?: string;
      }
    >(`/exam-students/batch-delete`, { params: request });
  },
  /**
   * @description 批量将指定的考试学生设置为排除状态，不参与统计（使用汇总表ID）
   */
  batchExcludeCreate: (request: ExamBatchExcludeStudentsRequest) => {
    return httpClient.post<
      ControllerResponse & {
        /** 批量排除学生的响应结构 */
        data?: ExamBatchExcludeStudentsResponse;
      }
    >(`/exam-students/batch-exclude`, { params: request });
  },
  /**
   * @description 通过Excel文件批量修改考生的考号信息。Excel格式：学校、系统号、姓名、班级、考号、科目
   */
  batchUpdateExamNumberCreate: (data: {
    /** 考试科目ID数组 */
    exam_subject_ids: number[];
    /** 学校ID */
    school_id: number;
    /**
     * Excel文件，包含学校、系统号、姓名、班级、考号、科目列
     * @format binary
     */
    file: File;
  }) => {
    return httpClient.formData<
      ControllerResponse & {
        /** 批量修改考号的响应结构 */
        data?: ExamBatchUpdateExamNumberResponse;
      }
    >(`/exam-students/batch-update-exam-number`, { params: data });
  },
  /**
   * @description 根据考试ID获取该考试的所有科目信息
   */
  examSubjectsDetail: (examId: number) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ExamGetExamSubjectsByExamIDResponse[];
      }
    >(`/exam-students/exam/${examId}/subjects`);
  },
  /**
   * @description 根据查询条件导出考试学生数据为Excel文件，支持多种筛选条件
   */
  exportList: (query: {
    /** 考试ID */
    exam_id?: number;
    /** 学校ID */
    school_id?: number;
    /**
     * 关键字
     * @maxLength 50
     */
    keyword?: string;
  }) => {
    return httpClient.download<Blob>(`/exam-students/export`, { query: query });
  },
  /**
   * @description 根据汇总表ID和科目ID删除指定科目的考生记录
   */
  subjectDeleteCreate: (request: ExamDeleteExamStudentBySubjectRequest) => {
    return httpClient.post<
      ControllerResponse & {
        message?: string;
      }
    >(`/exam-students/subject-delete`, { params: request });
  },
  /**
   * @description 根据考试条件同步学生数据，先删除该考试的所有考生再重新同步
   */
  syncCreate: (request: ExamSyncExamStudentsRequest) => {
    return httpClient.post<
      ControllerResponse & {
        /** 同步考试学生的响应结构 */
        data?: ExamSyncExamStudentsResponse;
      }
    >(`/exam-students/sync`, { params: request });
  },
  /**
   * @description 接收Excel文件，解析其中的考试学生数据并返回解析结果。Excel格式：学校、系统号、姓名、班级、考号、科目
   */
  uploadExcelCreate: (data: {
    /**
     * 考试ID
     * @min 1
     */
    exam_id: number;
    /**
     * Excel文件
     * @format binary
     */
    file: File;
  }) => {
    return httpClient.formData<
      ControllerResponse & {
        /** Excel文件解析结果响应 */
        data?: ExamUploadExcelResponse;
      }
    >(`/exam-students/upload-excel`, { params: data });
  },
  /**
   * @description 根据ID获取单个考试学生记录详情
   */
  examStudentsDetail: (id: number) => {
    return httpClient.get<
      ControllerResponse & {
        /** 考试学生关联信息响应 */
        data?: ExamExamStudentResponse;
      }
    >(`/exam-students/${id}`);
  },
  /**
   * @description 根据汇总表ID更新考试学生关联记录
   */
  examStudentsUpdate: (id: number, request: ExamUpdateExamStudentRequest) => {
    return httpClient.put<
      ControllerResponse & {
        /** 考试学生关联信息响应 */
        data?: ExamExamStudentResponse;
      }
    >(`/exam-students/${id}`, { params: request });
  },
  /**
   * @description 根据汇总表ID删除考试学生记录
   */
  examStudentsDelete: (id: number) => {
    return httpClient.delete<
      ControllerResponse & {
        message?: string;
      }
    >(`/exam-students/${id}`);
  },
  /**
   * @description 根据考试ID获取该考试的所有学生记录
   */
  studentsDetail: (examId: number) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ExamExamStudentResponse[];
      }
    >(`/exams/${examId}/students`);
  }
};
