import { httpApp } from "@/plugins/axiosApp";
import { responseToFile } from "@/utils/utils";
import { ImportResponse, ProjectCourse, ServerPageResponse } from "@/types";

/** 科目分页查询 */
export function getProjectCourseList(params: {
  courseId?: number;
  projectId: number;
  courseName?: string;
  pageNo?: number;
  pageSize?: number;
}) {
  return httpApp.post<any, ServerPageResponse<ProjectCourse>>(
    "/api/ess/projectCourse/list",
    params
  );
}

/** 导入项目参数配置 */
export function importProjectParams(projectId: number, file: File) {
  const f = new FormData();
  f.append("projectId", projectId + "");
  f.append("file", file);
  return httpApp.post<any, ImportResponse>(`/api/ess/projectCourse/import`, f);
}

/** 导出项目参数配置 */
export function exportProjectParams(projectId: number) {
  return httpApp
    .get(
      `/api/ess/projectCourse/export?` +
        new URLSearchParams({ projectId: projectId + "" }),
      {
        responseType: "blob",
      }
    )
    .then(function (response) {
      return responseToFile(response);
    });
}

/** 更新科目 */
export function updateProjectCourse(params: {
  id: number;
  nationalScore: number;
  nationalTotalScore: number;
  retestScore: number;
  retestTotalScore: number;
  totalScoreLine: number;
}) {
  return httpApp.post("/api/ess/projectCourse/update", params);
}
