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 = "",
  pageNumber = 1,
  pageSize = 10,
}) {
  const data = pickBy(
    {
      examId,
      activityId,
      roomCode,
      name,
      courseCode,
      identity,
      grade,
      classNo,
      pageNumber,
      pageSize,
    },
    (v) => v !== ""
  );
  return httpApp.post(
    "/api/admin/examStudent/query?" + object2QueryString(data)
  );
}

export function saveExamStudent({
  id = "",
  examId = "",
  activityId = "",
  roomCode = "",
  courseCode = "",
  name = "",
  identity = "",
  grade = "",
  classNo = "",
  enable = 1,
}) {
  const data = pickBy(
    {
      id,
      examId,
      activityId,
      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/save", [{ id, enable }]);
}

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