import { request } from "@/utils/request";

import { ExamSubjectPageParams } from "./types/common";
import {
  RecognizeConditionItem,
  RecognizeCheckListPageResult,
  RecognizeCheckTaskSaveParams,
  RecognizeCheckTaskActionResult,
  RecognizeCheckBuildTaskResult,
  RecognizeCheckResetTaskResult,
  RecognizeCheckDeleteTaskResult,
  RecognizeArbitrateItem,
  RecognizeArbitrateSaveParams,
  RecognizeArbitrateSaveResult,
  RecognizeArbitrateProgressResult,
  RecognizeArbitrateHistoryParams,
} from "./types/recognizeCheck";

// 识别对照管理
export const recognizeCheckListPage = (
  data: ExamSubjectPageParams
): Promise<RecognizeCheckListPageResult> =>
  request({
    url: "/api/admin/check/omr/group/page",
    method: "post",
    data,
  });

// 识别对照任务
// 所有可用的识别对照条件
export const recognizeConditionsList = (): Promise<RecognizeConditionItem[]> =>
  request({
    url: "/api/admin/check/omr/conditions",
    method: "post",
  });
// 创建/修改识别对照任务组
export const recognizeCheckTaskSave = (
  data: RecognizeCheckTaskSaveParams
): Promise<RecognizeCheckTaskActionResult> =>
  request({
    url: "/api/admin/check/omr/group/save",
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json;charset=UTF-8",
    },
  });

// 修改识别对照任务组阶段
export const recognizeCheckTaskStatusSave = (
  id: number
): Promise<{ stage: string; updateTime: number }> =>
  request({
    url: "/api/admin/check/omr/group/toggle",
    method: "post",
    data: { id },
  });

// 识别对照任务组生成任务
export const recognizeCheckBuildTask = (
  id: number
): Promise<RecognizeCheckBuildTaskResult> =>
  request({
    url: "/api/admin/check/omr/group/build",
    method: "post",
    data: { id },
  });

// 重置识别对照任务组
export const recognizeCheckResetTask = (
  id: number
): Promise<RecognizeCheckResetTaskResult> =>
  request({
    url: "/api/admin/check/omr/group/reset",
    method: "post",
    data: { id },
  });

// 删除识别对照任务组
export const recognizeCheckTaskDelete = (
  id: number
): Promise<RecognizeCheckDeleteTaskResult> =>
  request({
    url: "/api/admin/check/omr/group/delete",
    method: "post",
    data: { id },
  });

// 仲裁
// 仲裁任务获取
export const recognizeArbitrateTask = (
  groupId: number
): Promise<RecognizeArbitrateItem> =>
  request({
    url: "/api/admin/check/omr/arbitrate/get",
    method: "post",
    data: { groupId },
  });

// 仲裁结果提交
export const recognizeArbitrateSave = (
  data: RecognizeArbitrateSaveParams
): Promise<RecognizeArbitrateSaveResult> =>
  request({
    url: "/api/admin/check/omr/arbitrate/save",
    method: "post",
    data,
  });

// 仲裁进度状态
export const recognizeArbitrateProgress = (
  groupId: number
): Promise<RecognizeArbitrateProgressResult> =>
  request({
    url: "/api/admin/check/omr/arbitrate/get",
    method: "post",
    data: { groupId },
  });

// 仲裁任务释放
export const recognizeArbitrateRelease = (
  groupId: number
): Promise<{ success: boolean }> =>
  request({
    url: "/api/admin/check/omr/arbitrate/release",
    method: "post",
    data: { groupId },
  });

// 仲裁任务历史
export const recognizeArbitrateHistory = (
  data: RecognizeArbitrateHistoryParams
): Promise<RecognizeArbitrateItem> =>
  request({
    url: "/api/admin/check/omr/arbitrate/history",
    method: "post",
    data,
  });
