import { httpApp } from "@/plugins/axiosApp";
import { OfflineExam } from "@/types/student-client";

/** 获取答题纸模板链接 */
export async function getAnswersUrlApi(rootOrgId: number) {
  return httpApp.get<string>(`/api/ecs_core/org/getAnswersUrl/${rootOrgId}`);
}
/** 获取离线考试科目 */
export async function getOfflineCourseApi() {
  return httpApp.get<any, { data: OfflineExam[] }>(
    "/api/branch_ecs_oe_admin/offlineExam/getOfflineCourse"
  );
}
/** 下载离线考试试卷 */
export async function exportOfflinePaperApi(paperId: string) {
  return httpApp.get<Blob>(
    `/api/branch_ecs_ques/paper/export/${paperId}/PAPER/offLine`,
    {
      responseType: "blob",
    }
  );
}
/** 开始离线考试 */
export async function startOfflineExamApi(examStudentId: number) {
  return httpApp.get<any>(
    `/api/branch_ecs_oe_admin/offlineExam/startOfflineExam`,
    {
      params: { examStudentId },
    }
  );
}

type UploadFileType = {
  OFFLINE_UPLOAD_FILE_TYPE: string;
};
/** 获取离线考试上传文件类型 */
export async function offlineExamUploadFileTypesApi(examId: number) {
  return httpApp.get<any, { data: UploadFileType }>(
    `/api/ecs_exam_work/exam/getExamPropertyFromCacheByStudentSession/${examId}/OFFLINE_UPLOAD_FILE_TYPE`
  );
}

export async function offlineExamBatchSubmitPaperApi(data: FormData) {
  return httpApp.post<any>(
    `/api/branch_ecs_oe_admin/offlineExam/batchSubmitPaper`,
    data,
    { headers: { "Content-Type": "multipart/form-data" } }
  );
}
