import { $httpWithMsg } from "../../plugins/axios";
import { QUESTION_API } from "@/constants/constants.js";

const transformFormData = (datas) => {
  let formData = new FormData();
  Object.keys(datas).forEach((k) => {
    formData.append(k, datas[k]);
  });
  return formData;
};

// synthesis paper
export const synthesizePaperPageListApi = (datas) => {
  return $httpWithMsg.post(
    `${QUESTION_API}/synthesize/paper/page`,
    transformFormData(datas)
  );
};
export const synthesizePaperDeleteApi = (ids) => {
  return $httpWithMsg.post(
    QUESTION_API + "/synthesize/paper/delete",
    {},
    {
      params: { ids: ids.join() },
    }
  );
};
export const synthesizePaperDownloadApi = (datas) => {
  return $httpWithMsg.post(
    QUESTION_API + "/synthesize/paper/download",
    transformFormData(datas),
    {
      responseType: "blob",
    }
  );
};

export const paperPageListApi = (datas) => {
  return $httpWithMsg.post(
    `${QUESTION_API}/synthesize/paper/source/page`,
    transformFormData(datas)
  );
  // return $httpWithMsg.post(`${QUESTION_API}/user/assignteacher/1/100`, datas);
};
export const courseQueryApi = (name, enable) => {
  return $httpWithMsg.get(`${QUESTION_API}/course/query`, {
    params: {
      name,
      enable: enable || undefined,
    },
  });
};
export const synthesisBuildPaperApi = (datas) => {
  return $httpWithMsg.post(`${QUESTION_API}/synthesize/paper/build`, datas);
};
