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

import {
  ExamParams,
  ExamSubjectParams,
  RequestActionResult,
} from "./types/common";
import {
  ReviewTaskListItem,
  ReviewProgressResult,
  ReviewTaskSaveParams,
  ReviewTaskHistoryParams,
  ReviewWarningTaskExportParams,
} from "./types/review";

// 复核任务
export const reviewTask = (
  data: ExamSubjectParams
): Promise<ReviewTaskListItem> =>
  request({
    url: "/api/admin/check/assigned/task/get",
    method: "post",
    data,
  });

// 复核校验进度状态
export const reviewProgress = (
  data: ExamSubjectParams
): Promise<ReviewProgressResult> =>
  request({
    url: "/api/admin/check/assigned/overview",
    method: "post",
    data,
  });

// 复核校验任务历史
export const reviewTaskHistory = (
  data: ExamParams
): Promise<ReviewTaskListItem[]> =>
  request({
    url: "/api/admin/check/assigned/task/history",
    method: "post",
    data,
  });

// 复核校验结果提交
export const reviewTaskSave = (
  data: ReviewTaskSaveParams
): Promise<RequestActionResult> =>
  request({
    url: "/api/admin/check/assigned/task/save",
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json;charset=UTF-8",
    },
  });

// 复核校验任务释放
export const reviewTaskRelease = (
  data: ExamParams
): Promise<{ success: boolean }> =>
  request({
    url: "/api/admin/check/assigned/task/release",
    method: "post",
    data,
  });

// 复核校验重置
export const reviewTaskReset = (
  data: ExamSubjectParams
): Promise<RequestActionResult> =>
  request({
    url: "/api/admin/check/assigned/reset",
    method: "post",
    data,
  });
// 复核校验重置状态
export const reviewTaskResetStatus = (
  data: ExamSubjectParams
): Promise<{ synching: boolean }> =>
  request({
    url: "/api/admin/check/assigned/reset/status",
    method: "post",
    data,
  });

// 复核校验异常导出
export const reviewWarningTaskExport = (
  data: ReviewWarningTaskExportParams
): Promise<AxiosResponse<Blob>> =>
  request({
    url: "/api/admin/check/assigned/export",
    method: "post",
    data,
    download: true,
  });

// 审核员复核 -------------------->
// 复核任务
export const reviewAuditTask = (
  data: ExamSubjectParams
): Promise<ReviewTaskListItem> =>
  request({
    url: "/api/auditor/check/assigned/task/get",
    method: "post",
    data,
  });

// 复核校验进度状态
export const reviewAuditProgress = (
  data: ExamSubjectParams
): Promise<ReviewProgressResult> =>
  request({
    url: "/api/auditor/check/assigned/overview",
    method: "post",
    data,
  });

// 复核校验结果提交
export const reviewAuditTaskSave = (
  data: ReviewTaskSaveParams
): Promise<RequestActionResult> =>
  request({
    url: "/api/auditor/check/assigned/task/save",
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json;charset=UTF-8",
    },
  });

// 复核校验任务历史
export const reviewAuditTaskHistory = (
  data: ExamParams
): Promise<ReviewTaskListItem[]> =>
  request({
    url: "/api/auditor/check/assigned/task/history",
    method: "post",
    data,
  });

// 复核校验任务释放
export const reviewAuditTaskRelease = (
  data: ExamParams
): Promise<{ success: boolean }> =>
  request({
    url: "/api/auditor/check/assigned/task/release",
    method: "post",
    data,
  });
