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

const paramFilter = (v) => v !== "" && v !== undefined && v !== null;

// monitor key
export function getUserMonitorKey(recordId) {
  return httpApp.post(
    "/api/admin/monitor/getMonitorKey?" + object2QueryString({ recordId }),
    {}
  );
}
// live url domain
export function getLiveDomains() {
  return httpApp.post("/api/admin/sys/getPlayUrls", {});
}
// exam-invigilation
export function examInvigilationCount() {
  return httpApp.post("/api/admin/report/examination_monitor/count", {});
}
export function examInvigilationWarnDistribution() {
  return httpApp.post(
    "/api/admin/report/examination_monitor/warn_distribution",
    {}
  );
}
export function examInvigilationWarnTrend() {
  return httpApp.post("/api/admin/report/examination_monitor/warn_trend", {});
}
export function examInvigilationVideoRandomList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/list/video/random?" + object2QueryString(data),
    {}
  );
}
export function examInvigilationWarnMessage() {
  return httpApp.post("/api/admin/report/examination_monitor/warn_msg", {});
}

// realtime-monitoring
export function invigilateList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/list?" + object2QueryString(data),
    {}
  );
}
export function invigilateCount(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/exam/list/count?" + object2QueryString(data),
    {}
  );
}
export function invigilateVideoList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/list/video?" + object2QueryString(data),
    {}
  );
}
export function monitorCallCount({ examId, callStatus }) {
  const data = pickBy({ examId, callStatus }, paramFilter);
  return httpApp.post(
    "/api/admin/monitor/call/count?" + object2QueryString(data),
    {}
  );
}
export function invigilationWarningMessage(examId) {
  const data = pickBy({ examId }, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/warn/message?" + object2QueryString(data),
    {}
  );
}

// online-patrol
export function patrolList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/patrol/list?" + object2QueryString(data),
    {}
  );
}
export function patrolReportList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/patrol?" + object2QueryString(data),
    {}
  );
}

// 强制/手动交卷接口
export function invigilateFinish(datas) {
  // type: MANUAL:手动,AUTO:自动,BREACH:违纪交卷,INTERRUPT:监考强制交卷
  const data = pickBy(datas, paramFilter);
  return httpApp.post("/api/admin/invigilate/finish", data);
}
// 结束监考接口
export function invigilateExamFinish(examId) {
  const data = pickBy({ examId }, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/exam/finish?" + object2QueryString(data),
    {}
  );
}

// 监考老师::事实监控台-考试批次列表
export function examMonitorBatchList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post("/api/admin/exam/query?" + object2QueryString(data), {});
}
// 监考老师::考试批次列表
export function examBatchList(userId) {
  const type = "monitor";
  const paramQuery = userId
    ? `?userId=${userId}&type=${type}`
    : `?type=${type}`;
  return httpApp.post("/api/admin/sys/exam/query" + paramQuery);
}
// 监考老师::根据权限获取场次和考场接口
export function examActivityRoomList(examId) {
  const data = pickBy({ examId }, paramFilter);
  return httpApp.post(
    "/api/admin/sys/exam/privilegeQuery?" + object2QueryString(data),
    {}
  );
}
// 考试属性统计接口
export function examPropCount(examId) {
  const data = pickBy({ examId }, paramFilter);
  return httpApp.post(
    "/api/admin/exam/prop/count?" + object2QueryString(data),
    {}
  );
}

export function communicationList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/monitor/call/list?" + object2QueryString(data),
    {},
    {
      noErrorMessage: true,
    }
  );
}

export function communicationCalling({ recordId, source }) {
  return httpApp.post(
    "/api/admin/monitor/call/calling",
    { recordId, source },
    {
      noErrorMessage: true,
    }
  );
}
export function communicationOver({ recordId, source }) {
  return httpApp.post(
    "/api/admin/monitor/call/cancel",
    { recordId, source },
    {
      noErrorMessage: true,
    }
  );
}

// invigilation-detail
export function invigilationHistoryList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/history/list?" + object2QueryString(data),
    {}
  );
}

// warning-manage
export function invigilationWarningList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/warn/list?" + object2QueryString(data),
    {}
  );
}
export function invigilationWarningCount(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/warn/notify?" + object2QueryString(data),
    {}
  );
}
// 清除未阅
export function clearInvigilationUnreadWarningList({
  approveStatus,
  warningIds,
}) {
  return httpApp.post("/api/admin/invigilate/warn/save/status", {
    approveStatus,
    warningIds,
  });
}
export function clearInvigilationFilterUnreadWarningList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/warn/approveStatus/list/update?" +
      object2QueryString(data)
  );
}

// warning-detail
// 获取当前学生直播视频流
export function warningStudentDetail({ recordId }) {
  const data = {
    recordId,
  };
  return httpApp.post(
    "/api/admin/monitor/call/query?" + object2QueryString(data),
    {}
  );
}
// 获取预警详情信息
export function invigilateDetail(recordId) {
  return httpApp.post(
    "/api/admin/invigilate/list/detail?examRecordId=" + recordId,
    {}
  );
}
// 学生违纪处理
export function updateBreachInfo(datas) {
  const data = pickBy(datas, paramFilter);

  return httpApp.post("/api/admin/invigilate/breach", data);
}
// 发送文字/音频消息
export function sendWarningMsg(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post("/api/admin/invigilate/notice", data);
}

// reexam-apply
export function reexamApplyList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/reexam/list?" + object2QueryString(data),
    {}
  );
}
export function applyReexam(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post("/api/admin/invigilate/reexam/apply", data);
}

// reexam-pending
export function reexamPendingList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/reexam/list_not_done?" + object2QueryString(data),
    {}
  );
}
export function reexamPendingCount(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/reexam/list_not_done_notify?" +
      object2QueryString(data),
    {}
  );
}
export function checkReexamApply(datas) {
  return httpApp.post("/api/admin/invigilate/reexam/auditing", datas);
}

export function reexamCheckDetail(reexamId) {
  return httpApp.post(
    "/api/admin/invigilate/reexam/detail?reexamId=" + reexamId
  );
}

// reexam-checked
export function reexamCheckedList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/reexam/list_done?" + object2QueryString(data),
    {}
  );
}

// progress-detail
export function progressDetailList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/progress/list?" + object2QueryString(data),
    {}
  );
}
export function downloadProgressResult(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/invigilate/progress/list/export?" + object2QueryString(data),
    {},
    {
      responseType: "blob",
    }
  );
}

// exam-report
// report-overview
// reexam-checked
export function reportOverviewData(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_view?" + object2QueryString(data),
    {}
  );
}
// report-statistics
export function reportStatisticsData(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_view_count?" + object2QueryString(data),
    {}
  );
}
// report-absent
export function reportAbsentData(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_deficiency_list?" + object2QueryString(data),
    {}
  );
}
// report-exception
export function reportExceptionData(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_exception_list?" + object2QueryString(data),
    {}
  );
}
export function reportExceptionDetail(datas) {
  // examStudentId
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_exception_list_detail?" + object2QueryString(data),
    {}
  );
}
// report-reexam
export function reportReexamData(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_reexam_list?" + object2QueryString(data),
    {}
  );
}
// report-breach
export function reportBreachData(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_breach_list?" + object2QueryString(data),
    {}
  );
}
export function reportBreachDetail(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_breach_list_detail?" + object2QueryString(data),
    {}
  );
}
// report-cancel-breach
export function reportCancelBreachData(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_revoke_breach_list?" + object2QueryString(data),
    {}
  );
}
export function reportCancelBreachDetail(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_revoke_breach_list_detail?" +
      object2QueryString(data),
    {}
  );
}

// student-log-manage
export function studentLogList(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_student_log_list?" + object2QueryString(data),
    {}
  );
}
export function studentLogDetail(datas) {
  const data = pickBy(datas, paramFilter);
  return httpApp.post(
    "/api/admin/report/exam_student_log_list_detail?" +
      object2QueryString(data),
    {}
  );
}
