import httpClient from '@/utils/http';

import {
  ControllerResponse,
  ExamBatchCreateMarkingTaskRecordRequest,
  ExamBatchMarkingTaskRecordResponse,
  ExamMarkingTaskAverageScoreResponse,
  ExamMarkingTaskHistoryRecord,
  ExamMarkingTaskListResponse,
  ExamNoScoreQuestionRequest,
  ExamQuestionAverageScoreComparisonResponse,
  ExamQuestionWithTasksResponse,
  ExamReviewHistoryScoreRequest,
  ExamReviewHistoryScoreResponse,
  ExamSetProblemRecordRequest,
  ExamSetProblemRecordResponse,
  ExamStartMarkingTaskRequest,
  ExamStudentMarkingQuestionResponse,
  ExamStudentMarkingQuestionsResponse,
  HistoryDetailParamsOrderByEnum,
  ModelPageResponse
} from './data-contracts';
export default {
  /**
   * @description 批量更新阅卷评测结果，需要验证调用者身份必须是老师，且老师ID和record_id对应的老师ID一致
   */
  batchCreate: (records: ExamBatchCreateMarkingTaskRecordRequest) => {
    return httpClient.post<
      ControllerResponse & {
        data?: ExamBatchMarkingTaskRecordResponse;
      }
    >(`/marking-task-records/batch`, { params: records });
  },
  /**
   * @description 根据查询条件获取当前登录老师的阅卷任务列表，支持分页和多种筛选条件
   */
  markingTasksList: (query: {
    /**
     * 页码，默认1
     * @min 1
     */
    page?: number;
    /**
     * 每页数量，默认10，最大100
     * @min 1
     * @max 100
     */
    page_size?: number;
    /**
     * 考试名称(模糊查询)
     * @maxLength 50
     */
    exam_name?: string;
    /** 阅卷状态：prepare-准备中, alloting-调拨中,first_judge-初评中,final_judge-复评中,suspend-暂停,completed-已完成,remarked-问题卷标记 */
    marking_status?: string;
    /** 评估类型：single-单评, double-双评, part-部分评, multi-多评, none-不评 */
    evaluate_method?: string;
  }) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ExamMarkingTaskListResponse;
      }
    >(`/marking-tasks`, { query: query });
  },
  /**
   * @description 根据考试ID、科目ID获取当前登录老师名下的所有题目及其阅卷任务列表
   */
  byQuestionList: (query: {
    /**
     * 考试ID
     * @min 1
     */
    exam_id: number;
    /**
     * 考试科目ID
     * @min 1
     */
    exam_subject_id: number;
  }) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ExamQuestionWithTasksResponse[];
      }
    >(`/marking-tasks/by-question`, { query: query });
  },
  /**
   * @description 根据题目ID获取单个题目的阅卷任务详情信息
   */
  byQuestionIdList: (query: {
    /**
     * 题目ID
     * @min 1
     */
    question_id: number;
  }) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ExamQuestionWithTasksResponse;
      }
    >(`/marking-tasks/by-question-id`, { query: query });
  },
  /**
   * @description 教师对某个题目选择暂不打分，系统将该题目从当前教师的阅卷任务中剔除
   */
  noScoreCreate: (request: ExamNoScoreQuestionRequest) => {
    return httpClient.post<
      ControllerResponse & {
        message?: string;
      }
    >(`/marking-tasks/no-score`, { params: request });
  },
  /**
   * @description 根据记录ID设置问题卷类型和附加说明信息
   */
  problemRecordCreate: (request: ExamSetProblemRecordRequest) => {
    return httpClient.post<
      ControllerResponse & {
        data?: ExamSetProblemRecordResponse;
      }
    >(`/marking-tasks/problem-record`, { params: request });
  },
  /**
   * @description 根据题目ID和任务ID查看该题目的均分信息，包括所有老师的平均分、评分人数、当前老师的平均分和评分人数，以及分数分布
   */
  questionTaskAverageScoreDetail: (questionId: number, taskId: number) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ExamMarkingTaskAverageScoreResponse;
      }
    >(`/marking-tasks/question/${questionId}/task/${taskId}/average-score`);
  },
  /**
   * @description 根据题目ID和任务ID计算所有老师和特定老师的平均分对比
   */
  questionTaskAverageScoreComparisonDetail: (questionId: number, taskId: number) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ExamQuestionAverageScoreComparisonResponse;
      }
    >(`/marking-tasks/question/${questionId}/task/${taskId}/average-score-comparison`);
  },
  /**
   * @description 根据考试ID、科目ID获取当前登录老师名下的题目列表，不包含任务详情
   */
  questionsListList: (query: {
    /**
     * 考试ID
     * @min 1
     */
    exam_id: number;
    /**
     * 考试科目ID
     * @min 1
     */
    exam_subject_id: number;
  }) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ExamQuestionWithTasksResponse[];
      }
    >(`/marking-tasks/questions-list`, { query: query });
  },
  /**
   * @description 根据任务ID获取当前老师对该题目的回评历史分数列表
   */
  reviewHistoryScoreCreate: (request: ExamReviewHistoryScoreRequest) => {
    return httpClient.post<
      ControllerResponse & {
        data?: ExamReviewHistoryScoreResponse;
      }
    >(`/marking-tasks/review/history-score`, { params: request });
  },
  /**
   * @description 教师点击开始阅卷时调用，检查任务状态并更新为阅卷中，同时创建Redis队列
   */
  startCreate: (request: ExamStartMarkingTaskRequest) => {
    return httpClient.post<
      ControllerResponse & {
        message?: string;
      }
    >(`/marking-tasks/start`, { params: request });
  },
  /**
   * @description 根据任务ID获取该老师在这个任务下阅过的试卷历史记录，按创建时间从小到大排序
   */
  historyDetail: (
    taskId: number,
    query: {
      /**
       * 页码，默认1
       * @min 1
       */
      page?: number;
      /**
       * 每页数量，默认10，最大100
       * @min 1
       * @max 100
       */
      page_size?: number;
      /** 是否为回评记录过滤条件,如果是回评才设置history_score、order_by参数 */
      is_review?: boolean;
      /**
       * 历史分数过滤条件
       * @format float64
       */
      history_score?: number;
      /**
       * 排序字段：1-按打分从小到大 排序，2-按打分从大到小排序，3-按时间从早到晚排序，4-按时间从晚到在排序
       * @default 1
       */
      order_by?: HistoryDetailParamsOrderByEnum;
      /** 已阅试卷序号，从1开始 */
      index?: number;
    }
  ) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ModelPageResponse & {
          list?: ExamMarkingTaskHistoryRecord[];
        };
      }
    >(`/marking-tasks/${taskId}/history`, { query: query });
  },
  /**
   * @description 从教师的缓存队列中取出一条数据，获取题目信息和图片路径
   */
  questionDetail: (taskId: number) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ExamStudentMarkingQuestionResponse;
      }
    >(`/marking-tasks/${taskId}/question`);
  },
  /**
   * @description 从教师的缓存队列中取出多条数据，获取题目信息和图片路径
   */
  questionsDetail: (
    taskId: number,
    query: {
      /**
       * 一次性返回的题目数量
       * @min 1
       * @max 100
       */
      count: number;
    }
  ) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ExamStudentMarkingQuestionsResponse;
      }
    >(`/marking-tasks/${taskId}/questions`, { query: query });
  },
  /**
   * @description 根据任务ID删除所有相关的阅卷任务记录，并将任务状态重置为准备中
   */
  remarkCreate: (taskId: number) => {
    return httpClient.post<
      ControllerResponse & {
        message?: string;
      }
    >(`/marking-tasks/${taskId}/remark`);
  }
};
