import { request } from "@/utils/request";
import { ExamParams } from "./types/common";
import {
  SubjectItem,
  ExamListParams,
  ExamListResult,
  UploadSheetParams,
  UploadSliceParams,
  UploadFileResult,
} from "./types/base";

export const getExamList = (data: ExamListParams): Promise<ExamListResult> =>
  request({
    url: "/api/admin/exam/list",
    data,
  });

export const getSubjectList = (data: ExamParams): Promise<SubjectItem[]> =>
  request({
    url: "/api/admin/subject/list",
    method: "post",
    data,
  });

// 原图上传
export const updateSheet = (
  data: UploadSheetParams
): Promise<UploadFileResult> => {
  const formData = new FormData();
  for (const key in data) {
    if (Object.prototype.hasOwnProperty.call(data, key)) {
      const val = data[key];
      formData.append(key, val);
    }
  }
  return request({
    url: "/api/admin/scan/answer/sheet/update",
    method: "post",
    data: formData,
  });
};
// 裁切图上传
export const updateSlice = (
  data: UploadSliceParams
): Promise<UploadFileResult> => {
  const formData = new FormData();
  for (const key in data) {
    if (Object.prototype.hasOwnProperty.call(data, key)) {
      const val = data[key];
      formData.append(key, val);
    }
  }
  return request({
    url: "/api/admin/scan/answer/slice/update",
    method: "post",
    data: formData,
  });
};

// 裁切图修改
export const uploadSlice = (
  data: UploadSliceParams
): Promise<UploadFileResult> => {
  const formData = new FormData();
  for (const key in data) {
    if (Object.prototype.hasOwnProperty.call(data, key)) {
      const val = data[key];
      formData.append(key, val);
    }
  }
  return request({
    url: "/api/admin/scan/answer/slice/upload",
    method: "post",
    data: formData,
  });
};
