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

// common select
export const courseQueryApi = (name, enable) => {
  return $httpWithMsg.get(`${QUESTION_API}/course/query`, {
    params: {
      name,
      enable: enable || undefined,
    },
  });
};
export const propertyNameQueryApi = (courseId, name) => {
  return $httpWithMsg.get(`${QUESTION_API}/courseProperty/enable`, {
    params: {
      courseId,
      name,
    },
  });
};
export const propertyFirstQueryApi = (coursePropertyId) => {
  return $httpWithMsg.get(`${QUESTION_API}/property/first/${coursePropertyId}`);
};
export const propertySecondQueryApi = (firstPropertyId) => {
  return $httpWithMsg.get(`${QUESTION_API}/property/second/${firstPropertyId}`);
};
export const propertyTreeQueryApi = (coursePropertyId) => {
  return $httpWithMsg.get(`${QUESTION_API}/property/all/${coursePropertyId}`);
};
export const questionDetailNameQueryApi = ({ courseId, questionType }) => {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/find_detail_name`,
    {},
    { params: { courseId, questionType } }
  );
};

// question-manage
export function questionPageListApi(data) {
  const url = `${QUESTION_API}/question/question/page`;
  return $httpWithMsg.get(url, { params: data });
}
export function classifyQuestionPageListApi(data) {
  const url = `${QUESTION_API}/question/classify/find_current_classify_question_page`;
  return $httpWithMsg.post(url, {}, { params: data });
}
export function deleteQuestionApi(questionIdList) {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/recycle`,
    {},
    { params: { questionIdList } }
  );
}
export function moveQuestionApi(questionIdList, targetClassifyId) {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/classify/move_questions_to_classify`,
    {},
    {
      params: { questionIdList, targetClassifyId },
    }
  );
}
export function copyQuestionApi(questionIdList, targetClassifyId) {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/copy`,
    {},
    {
      params: { questionIdList, targetClassifyId },
    }
  );
}
export function importQuestionApi(data, headData) {
  return $httpWithMsg.post(`${QUESTION_API}/import/paper`, data, {
    headers: headData,
  });
}
export function updateQuestionApi(data) {
  return $httpWithMsg.post(`${QUESTION_API}/question/save`, data, {
    params: { courseId: data.courseId },
  });
  // return Promise.resolve(data);
}
// statistics
// import distributionData from "./datas/distributionData.json";
export function questionDistributionStatisticsApi(courseId) {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/statistic/distribution`,
    {},
    {
      params: { courseId },
    }
  );
  // return Promise.resolve({ data: distributionData, courseId });
}
// import distributionPropData from "./datas/distributionPropData.json";
export function questionPropertyDistributionStatisticsApi(data) {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/statistic/property_distribution`,
    {},
    {
      params: data,
    }
  );
  // return Promise.resolve({ data: distributionPropData, filter: data });
}
// classify-manage
export function classifyListApi(parentId) {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/classify/list`,
    {},
    {
      params: { parentId },
    }
  );
}
export function classifyTreeApi() {
  return $httpWithMsg.post(`${QUESTION_API}/question/classify/find_all`, {});
}
export function updateClassifyApi(datas) {
  return $httpWithMsg.post(`${QUESTION_API}/question/classify/save`, datas);
}
export function deleteClassifyApi(questionClassifyIdList) {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/classify/recycle`,
    {},
    {
      params: {
        questionClassifyIdList,
      },
    }
  );
}
export function moveClassifyApi(movedClassifyId, targetClassifyId) {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/classify/move`,
    {},
    {
      params: { movedClassifyId, targetClassifyId },
    }
  );
}

// question-recycle
export function questionRecycleListApi(data = {}) {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/recycle_find`,
    {},
    { params: data }
  );
}
export function recoverQuestionApi(recycleParamList) {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/recycle_recover`,
    recycleParamList
  );
}
export function thoroughDeleteQuestionApi(recycleParamList) {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/recycle_clear`,
    recycleParamList
  );
}
export function clearQuestionRecycleApi() {
  return $httpWithMsg.post(`${QUESTION_API}/question/recycle_clear_all`, {});
}

// question-audit
export const auditQuestionWaitPageListApi = (datas) => {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/find_pending_trial_question`,
    {},
    {
      params: datas,
    }
  );
};
export const auditQuestionAuditedPageListApi = (datas) => {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/find_my_audit_question`,
    {},
    {
      params: datas,
    }
  );
};
export const auditQuestionApplyPageListApi = (datas) => {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/find_my_question_status`,
    {},
    {
      params: datas,
    }
  );
};
export const auditQuestionsUnsubmitPageListApi = (datas) => {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/find_will_submit_question`,
    {},
    {
      params: datas,
    }
  );
};

export const auditQuestionApi = (datas) => {
  // auditResult,auditRemark,questionIds
  return $httpWithMsg.post(
    `${QUESTION_API}/question/audit/save`,
    {},
    {
      params: datas,
    }
  );
};
export const withdrawQuestionApi = (questionIds) => {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/withdraw`,
    {},
    { params: { questionIds } }
  );
};
export const submitQuestionApi = (questionIds) => {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/submit`,
    {},
    { params: { questionIds } }
  );
};

// question/security_settings
export const questionSecuritySettingsApi = (datas) => {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/security_settings`,
    {},
    {
      params: datas,
    }
  );
};
export const questionSecurityCheckApi = (safePassword) => {
  return $httpWithMsg.post(
    `${QUESTION_API}/question/check_password`,
    {},
    {
      params: { safePassword },
    }
  );
};

// source-detail
export function sourceDetailPageListApi(data) {
  const url = `${QUESTION_API}/source/detail/page`;
  return $httpWithMsg.post(url, {}, { params: data });
}
export function deleteSourceDetailApi(ids) {
  return $httpWithMsg.post(
    `${QUESTION_API}/source/detail/delete`,
    {},
    { params: { ids: ids.join() } }
  );
}
export function updateSourceDetailApi(data) {
  return $httpWithMsg.post(
    `${QUESTION_API}/source/detail/save`,
    {},
    { params: data }
  );
}
