// @ts-nocheck
import { httpApp } from "@/plugins/axiosApp";

export function login() {
  return httpApp.get("/api/user/login");
}

export function getExams(pageNumber: number, pageSize: number) {
  return httpApp.get(
    "/api/exams?" +
      new URLSearchParams({
        pageNumber: "" + pageNumber,
        pageSize: "" + pageSize,
      })
  );
}

export function getStudents(
  examId: number,
  pageNumber: number,
  pageSize: number,
  params: any
) {
  const form = {
    examId: examId,
    pageNumber: pageNumber,
    pageSize: pageSize,
  };
  if (params != undefined) {
    for (const key in params) {
      if (params[key] && params[key] != "") {
        form[key] = params[key];
      }
    }
  }
  return httpApp.post("/api/exam/students", new URLSearchParams(form));
}

export function countStudents(examId: number, params) {
  params = params || {};
  params.examId = examId;
  return httpApp.post("/api/exam/students/count", new URLSearchParams(params));
}

export function getPackages(examId, upload, withUrl) {
  let uri = "/api/package/count/" + examId;
  const param = [];
  if (upload != undefined) {
    param.push("upload=" + (upload ? "true" : "false"));
  }
  if (withUrl != undefined) {
    param.push("withUrl=" + (withUrl ? "true" : "false"));
  }
  if (param.length > 0) {
    uri = uri + "?" + param.join("&");
  }
  return httpApp.get(uri);
}
