import { httpApp } from "@/plugins/axiosApp";
import { CommonResponse, MarkDetail, Setting, Task } from "@/types";

interface paramType {
  paperNumber?: string;
  groupNumber?: number;
  examId?: string;
  arbitrateId?: string;
}

/** 清理仲裁任务(taskId 与其他参数互斥填写) */
export async function clearArbitrateTask(params: paramType) {
  return httpApp.post<void>(
    "/api/admin/mark/arbitrate/clear",
    {},
    {
      params,
    }
  );
}

/** 查看单个学生的仲裁任务 */
export async function getSingleArbitrateTask(params: paramType) {
  return httpApp.post<Task>(
    "/api/admin/mark/arbitrate/getTask",
    {},
    { params }
  );
}

/** 查看仲裁任务2次分数 */
export async function getArbitrateList(arbitrateId: string) {
  return httpApp.post<MarkDetail[]>(
    "/api/admin/mark/arbitrate/getArbitrationList",
    {},
    { params: { arbitrateId } }
  );
}

/** 批量仲裁得到单个学生的仲裁任务 */
export async function getOneOfArbitrateTask(params: paramType) {
  return httpApp.post<Task>(
    "/api/admin/mark/arbitrate/getTask",
    {},
    {
      setGlobalMask: true,
      params,
    }
  );
}

/** 批量仲裁得到任务总数 */
export async function getArbitrateTaskStatus(params: paramType) {
  return httpApp.post<{
    valid: boolean;
    totalCount: number;
    markedCount: number;
  }>(
    "/api/admin/mark/arbitrate/getStatus",
    {},
    {
      params,
    }
  );
}

/** 批量仲裁设置 */
export async function getArbitrateSetting(params: paramType) {
  return httpApp.post<Setting>(
    "/api/admin/mark/arbitrate/getSetting",
    {},
    {
      params,
    }
  );
}

/** 批量仲裁历史 */
export async function getArbitrateHistory({
  subjectCode,
  groupNumber,
  examId,
  pageNumber = 1,
  pageSize = 20,
  order = "markerTime",
  sort = "DESC",
  secretNumber = null,
}) {
  if (!subjectCode) return;

  return httpApp.post<Task[]>(
    "/api/admin/mark/arbitrate/getHistory",
    {},
    {
      params: {
        paperNumber: subjectCode,
        pageSize,
        order,
        sort,
        pageNumber,
        examId,
        groupNumber,
        secretNumber: secretNumber || undefined,
      },
    }
  );
}

/** 保存仲裁任务 */
export async function saveArbitrateTask(
  taskId: string,
  studentId: string,
  markerScore: number,
  scoreList: Array<number>,
  unselective: boolean,
  trackList?: any,
  specialTagList?: any
) {
  return httpApp.post<CommonResponse>("/api/admin/mark/arbitrate/saveTask", {
    taskId,
    studentId,
    markerScore,
    scoreList,
    unselective,
    trackList,
    specialTagList,
  });
}
