import { httpApp } from "@/plugins/axiosIndex";
import { pickBy } from "lodash-es";
import { object2QueryString } from "@/utils/utils";

export function searchTasks({
  entityId = "",
  type = "",
  pageNumber = 1,
  pageSize = 10,
}) {
  const data = pickBy(
    { entityId, type, pageNumber, pageSize },
    (v) => v !== ""
  );
  return httpApp.post("/api/admin/task/query?" + object2QueryString(data));
}

export function importPaper({
  examId,
  processPaper,
  processAnswer,
  encryptMode = "auto",
  objectiveShuffle = "",
  optionShuffle = "",
  audioPlayCount = "",
  fileName,
  file,
  md5,
}) {
  const form = new FormData();
  form.append("examId", examId);
  form.append("processPaper", processPaper);
  form.append("processAnswer", processAnswer);
  form.append("encryptMode", encryptMode);
  form.append("objectiveShuffle", objectiveShuffle);
  form.append("optionShuffle", optionShuffle);
  form.append("audioPlayCount", audioPlayCount);
  form.append("fileName", fileName);
  form.append("file", file);
  return httpApp.post("/api/admin/exam/paper/import", form, {
    headers: { "Content-Type": "multipart/form-data", md5 },
  });
}

export function importExamStudent({ examId, fileName, file, md5 }) {
  const form = new FormData();
  form.append("examId", examId);
  form.append("fileName", fileName);
  form.append("file", file);
  return httpApp.post("/api/admin/examStudent/import", form, {
    headers: { "Content-Type": "multipart/form-data", md5 },
  });
}

export function importInvigilator({ examId, fileName, file, md5 }) {
  const form = new FormData();
  form.append("examId", examId);
  form.append("fileName", fileName);
  form.append("file", file);
  return httpApp.post("/api/admin/invigilateUser/import", form, {
    headers: { "Content-Type": "multipart/form-data", md5 },
  });
}

export function exportInvigilate({ examId, roomCode, userId }) {
  const form = new FormData();
  form.append("examId", examId);
  form.append("roomCode", roomCode);
  form.append("userId", userId);
  return httpApp.post("/api/admin/invigilateUser/export", form);
}
