import { download, post, upload, get } from '@/api/request';

const env = import.meta.env;
const PREFIX = env.VITE_API_PREFIX_PROJECT;

/**
 * 获取项目任务下的算例信息
 * @param params
 * @returns
 */
export const getTaskRunTreeApi = (params: any) => {
  return post(`${PREFIX}run/getTaskRunTree`, params);
};

/**
 * 新建算例
 * @param params
 * @returns
 */
export const addTaskRunApi = (params: any) => {
  return post(`${PREFIX}run/addTaskRun`, params);
};

/**
 * 查询算例信息
 * @param params
 * @returns
 */
export const queryTaskRunApi = (params: any) => {
  return post(`${PREFIX}run/queryTaskRun`, params);
};

/**
 * 创建算例下的结果文件夹
 * @param params dirName文件夹名称 dirType文件夹类型默认2 uuId算例的uuid
 * @returns
 */
export const createRunDirApi = (params: any) => {
  return post(`${PREFIX}run/createRunDir`, params);
};

/**
 * 查询算例结果文件夹及文件
 * @param params uuId算例的uuid size 10 current 1
 * @returns
 */
export const queryRunDirApi = (params: any) => {
  return post(`${PREFIX}run/queryRunDir`, params);
};

/**
 * 上传算例结果文件
 * @param params file文件 dirId文件夹id fileName文件名称 fileType 1：模型文件 2：仿真报告 3：计算文件 4：曲线文件 5：云图文件
 * @returns
 */
export const uploadRunFilesApi = (params: any) => {
  return post(`${PREFIX}run/uploadRunFiles`, params);
};

/**
 * 删除算例
 * @param params runId 算例的id
 * @returns
 */
export const deleteTaskRunApi = (params: any) => {
  return post(`${PREFIX}run/deleteTaskRun`, params);
};

/**
 * 查询任务下的算例版本树
 * @param params taskId算例uuid
 * @returns
 */
export const getTaskRunVersionApi = (params: any) => {
  return post(`${PREFIX}run/getTaskRunVersion`, params);
};

/**
 * 查询算例版本树
 * @param params runId算例的uuid
 * @returns
 */
export const getRunVersionApi = (params: any) => {
  return post(`${PREFIX}run/getRunVersion`, params);
};

/**
 *算例录入关键结果
 * @param params
 * @returns
 */
export const addSimulationKeyResultApi = (params: any) => {
  return upload(`${PREFIX}run/addSimulationKeyResult`, params);
};

/**
 * 查询算例关键结果列表
 * @param params runId  keyResultType size current
 * @returns
 */
export const listSimulationKeyResultApi = (params: any) => {
  return post(`${PREFIX}run/listSimulationKeyResult`, params);
};

/**
 *删除算例关键结果列表
 * @param params
 * @returns
 */
export const deleteSimulationKeyResultApi = (params: any) => {
  return post(`${PREFIX}run/deleteSimulationKeyResult`, params);
};

/**
 * 生成自动化报告
 * @param params imageFileIdList 图片文件id列表 performanceList 性能指标列表 parentNodeInfoList
 * @returns
 */
export const generateReportApi = (params: any) => {
  return download(`${PREFIX}run/generateReport`, params, params.fileName);
};

/**
 * 上传交付物第一步 keyResultList uploadTaskId runId templateId templateName type 0
 * @param params
 */
export const batchAddSimulationKeyResultApi = (params: any) => {
  return post(`${PREFIX}run/batchAddSimulationKeyResult`, params);
};

/**
 * 根据交付物文件id查询相关属性和任务信息
 * @param params fileId 文件id
 * @returns
 */
export const queryKeyResultAndTaskInfoApi = (params: any) => {
  return post(`${PREFIX}run/queryKeyResultAndTaskInfo`, params);
};

/**
 * 查询流程节点列表
 * @param params runId 算例的uuid
 * @returns
 */
export const listSimulationFlowNodeApi = (params: any) => {
  return post(`${PREFIX}run/listFlowNodes`, params);
};

/**
 * 保存节点参数
 * @param params nodeUuid 节点的uuid runId 算例的uuid inputParams：保存的参数内容
 * @returns
 */
export const saveNodeParamsApi = (params: any) => {
  return post(`${PREFIX}run/saveNodeParams`, params);
};

/**
 * 启动流程
 * @param params runId run的uuid
 * @returns
 */
export const startProcessInstanceApi = (params: any) => {
  return post(`${PREFIX}run/startProcessInstance`, params);
};

/**
 *
 * @param params 交付物审批 taskId 任务id difficult 难度系数 templateId流程模板
 * @returns
 */
export const deliverableApproveApi = (params: any) => {
  return post(`${PREFIX}run/deliverableApprove`, params);
};

/**
 * 编辑算例关键结果属性
 * @param params  算例结果的全部属性
 * @returns
 */
export const editSimulationKeyResultApi = (params: any) => {
  return upload(`${PREFIX}run/editSimulationKeyResult`, params);
};

/**
 * 查询物理量相关信息
 * @returns
 */
export const listQuantitiesApi = () => {
  return get(`${PREFIX}run/listQuantities`);
};

/**
 * 根据物理量获取对应单位
 * @param params quantityType 物理量名称
 * @returns
 */
export const listUnitsApi = (params: any) => {
  return get(`${PREFIX}run/listUnits`, params);
};

/**
 * 上传试验结果第一步
 * @param params fileInfoList 附件列表 imageFileInfo 截图列表 expName 试验名称 expData 实验数据 expDesc 试验描述 uploadTaskId 时间戳 taskId 任务的uuid
 * @returns
 */
export const batchAddExperimentResultApi = (params: any) => {
  return post(`${PREFIX}run/batchAddExperimentResult`, params);
};

/**
 * 试验结果查询
 * @param params taskId  current size
 * @returns
 */
export const listExperimentResultApi = (params: any) => {
  return post(`${PREFIX}run/listExperimentResult`, params);
};

/**
 * 删除试验结果
 * @param params id
 * @returns
 */
export const deleteExperimentResultApi = (params: any) => {
  return post(`${PREFIX}run/deleteExperimentResult`, params);
};

/**
 * 编辑试验结果（先删后增）
 * @param params fileInfoList 附件列表 imageFileInfo 截图列表 expName 试验名称 expData 实验数据 expDesc 试验描述 uploadTaskId 时间戳 taskId 任务的uuid
 * @returns
 */
export const editExperimentResultApi = (params: any) => {
  return post(`${PREFIX}run/editExperimentResult`, params);
};

// 保存算例编辑报告
export const editReportApi = (params: any) => {
  return post(`${PREFIX}run/editReport`, params);
};

// 保存并下载算例编辑报告
export const editReportAndDownloadApi = (params: any) => {
  return download(`${PREFIX}run/editReportAndDownload`, params, params.fileName);
};

// 算例下编辑报告
export const runDetailApi = (params: any) => {
  return post(`${PREFIX}run/detail`, params);
};

/**
 *
 * @param params 同步关键结果到任务 keyResultIdList runId
 * @returns
 */
export const syncKeyResultToTaskApi = (params: any) => {
  return post(`${PREFIX}run/syncKeyResultToTask`, params);
};

/**
 * 导出算例报告新
 * @param params runId reportContent
 * @returns files
 */
export const generateNewReportApi = (params: any) => {
  return download(`${PREFIX}run/generateNewReport`, params, params.fileName);
};
