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

export function searchExamStudents({
  examId = "",
  activityId = "",
  roomCode = "",
  courseCode = "",
  name = "",
  identity = "",
  grade = "",
  classNo = "",
  hasPhoto = "",
  pageNumber = 1,
  pageSize = 10,
}) {
  const data = pickBy(
    {
      examId,
      activityId,
      roomCode,
      name,
      courseCode,
      identity,
      grade,
      classNo,
      hasPhoto,
      pageNumber,
      pageSize,
    },
    (v) => v !== "" && v !== null
  );
  return httpApp.post(
    "/api/admin/examStudent/query?" + object2QueryString(data)
  );
}

export function exportExamStudent({
  examId = "",
  activityId = "",
  roomCode = "",
  courseCode = "",
  name = "",
  identity = "",
  grade = "",
  classNo = "",
  hasPhoto = "",
}) {
  const data = pickBy(
    {
      examId,
      activityId,
      roomCode,
      name,
      courseCode,
      identity,
      grade,
      classNo,
      hasPhoto,
    },
    (v) => v !== "" && v !== null
  );
  return httpApp.post(
    "/api/admin/examStudent/export?" + object2QueryString(data)
  );
}

export function saveExamStudent({
  id = "",
  examId = "",
  examActivityId = "",
  roomCode = "",
  courseCode = "",
  name = "",
  identity = "",
  grade = "",
  classNo = "",
  enable = 1,
}) {
  const data = pickBy(
    {
      id,
      examId,
      examActivityId,
      roomCode,
      name,
      courseCode,
      identity,
      grade,
      classNo,
      enable,
    },
    (v) => v !== ""
  );

  return httpApp.post("/api/admin/examStudent/save", [data]);
}

export function toggleEnableExamStudent({ id, enable }) {
  return httpApp.post("/api/admin/examStudent/toggle", [{ id, enable }]);
}

export function toggleEnableExamStudentArray(ary = []) {
  return httpApp.post("/api/admin/examStudent/toggle", ary);
}
