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

export function searchExams({
  name = "",
  enable = "",
  mode = "",
  pageNumber = 1,
  pageSize = 10,
}) {
  const data = pickBy(
    { name, enable, mode, pageNumber, pageSize },
    (v) => v !== ""
  );
  return httpApp.post("/api/admin/exam/query?" + object2QueryString(data));
}

export function getExamDetail({ id }) {
  return httpApp.post("/api/admin/exam/detail?" + object2QueryString({ id }));
}

export function toggleEnableExam({ id, enable }) {
  return httpApp.post("/api/admin/exam/toggle", { id, enable });
}

export function copyExam({ sourceId, name, code }) {
  return httpApp.post("/api/admin/exam/copy", { sourceId, name, code });
}

export function saveExam({
  id = "",
  breakExpireSeconds = 0,
  breakResumeCount = 0,
  cameraPhotoUpload = 0,
  code = "",
  createId = 0,
  createTime = "",
  enable = "",
  enableIpLimit = 0,
  endTime = "",
  entryAuthenticationPolicy = "",
  examCount = 0,
  forceFinish = 0,
  inProcessFaceStrangerIgnore = 0,
  inProcessRealnessVerify = 0,
  inProcessFaceVerify = 0,
  inProcessLivenessFixedRange = [],
  inProcessLivenessJudgePolicy = "",
  inProcessLivenessVerify = 0,
  ipAllow = "",
  maxDurationSeconds = 0,
  minDurationSeconds = 0,
  mode = "",
  monitorRecord = 0,
  monitorVideoSource = [],
  name = "",
  objectiveScorePolicy = "",
  openingSeconds = 0,
  // "orgId =   0,
  postNotice = "",
  preNotice = "",
  preNoticeStaySeconds = 0,
  prepareSeconds = 0,
  progress = 0,
  recordSelectStrategy = "",
  reexamAuditing = 0,
  scoreStatus = "",
  shortCode = "",
  showObjectiveScore = 0,
  startTime = "",
  mobilePhotoUpload = 0,
}) {
  const data = pickBy(
    {
      id,
      breakExpireSeconds,
      breakResumeCount,
      cameraPhotoUpload,
      code,
      createId,
      createTime,
      enable,
      enableIpLimit,
      endTime,
      entryAuthenticationPolicy,
      examCount,
      forceFinish,
      inProcessFaceStrangerIgnore,
      inProcessRealnessVerify,
      inProcessFaceVerify,
      inProcessLivenessFixedRange,
      inProcessLivenessJudgePolicy,
      inProcessLivenessVerify,
      ipAllow,
      maxDurationSeconds,
      minDurationSeconds,
      mode,
      monitorRecord,
      monitorVideoSource,
      name,
      objectiveScorePolicy,
      openingSeconds,
      // "orgId =   0,
      postNotice,
      preNotice,
      preNoticeStaySeconds,
      prepareSeconds,
      progress,
      recordSelectStrategy,
      reexamAuditing,
      scoreStatus,
      shortCode,
      showObjectiveScore,
      startTime,
      mobilePhotoUpload,
    },
    (v) => v !== ""
  );
  return httpApp.post("/api/admin/exam/save", data);
}

export function getExamRoom() {
  return httpApp.post("/api/admin/sys/examRoom/query");
}

export function reCalcExam(examId) {
  return httpApp.post("/api/admin/exam/score/calculate?id=" + examId);
}
