import { httpApp } from "@/plugins/axiosApp";
import {
  ImportResponse,
  Paper,
  SASPaper,
  SASQuestion,
  SASQuestionGroup,
} from "@/types";

/** 试卷查询 */
export function getPaper(id: number) {
  return httpApp.post<any, { data: Paper }>("/api/ess/paper/" + id);
}

/** 试卷分析-查询指定试卷全卷信息 */
export function getSasPaper(id: number) {
  return httpApp.post<any, { data: SASPaper }>(
    "/api/ess/sasPaper/findOne",
    new URLSearchParams([["paperId", id + ""]])
  );
}

/** 试题题目编排,试卷特征量数,试题难度分组分布 */
export function getPaperQuestions(paperId: number) {
  return httpApp.post<any, { data: SASQuestion[] }>(
    "/api/ess/sasQuestion/list",
    new URLSearchParams([["paperId", paperId + ""]])
  );
}

/** 题型难度分布、题型区分度分布 */
export function getPaperQuestionGroups(projectId: number, paperId: number) {
  return httpApp.post<any, { data: SASQuestionGroup[] }>(
    "/api/ess/sasQuestionGroup/list",
    new URLSearchParams([
      ["projectId", projectId + ""],
      ["paperId", paperId + ""],
    ])
  );
}

/** 试题难度分组分布-难度分组设置 */
export function setPaperRangeConfig(params: {
  projectId: number;
  courseId?: number;
  paperId?: number;
  rangeConfig: string;
}) {
  return httpApp.post("/api/ess/paper/difficulityRangeConfig", params);
}

/** 导入题型设置 */
export function importQuestionGroups(projectId: number, file: File) {
  const f = new FormData();
  f.append("projectId", projectId + "");
  f.append("file", file);
  return httpApp.post<any, ImportResponse>(
    `/api/ess/sasQuestionGroup/import`,
    f
  );
}
