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

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

// 获取文件夹列表
// TODO  dirType=1临时方案  待FileTree优化完成后删除
export const dataListDirApi = (params: any) => {
  return get(`${PREFIX}data/listDir?dirType=1`, params);
};

// 重命名文件夹
export const dataRenameFileApi = (params: any) => {
  return post(`${PREFIX}data/renameFile`, params);
};

// 上传图片
export const dataUploadAvatarApi = (params: any, onProgress?: any) => {
  return upload(`${PREFIX}data/uploadAvatar`, params, onProgress);
};

// 上传脚本文件
export const dataUploadScriptFileApi = (params: any, onProgress?: any) => {
  return upload(`${PREFIX}data/uploadScriptFile`, params, onProgress);
};

export const dataUploadFilesApi = (params: any, onProgress?: any) => {
  return upload(`${PREFIX}data/uploadFiles`, params, onProgress);
};

export const dataCreateDirApi = (params: any) => {
  return post(`${PREFIX}data/createDir`, params);
};

export const dataDelDirApi = (params: any) => {
  return post(`${PREFIX}data/delDir`, params);
};

export const dataRenameDirApi = (params: any) => {
  return post(`${PREFIX}data/renameDirNew`, params);
};
/**
 * queryTarget 1-文件夹，2-文件 不传查询全部 DataType
 * @param params
 * @returns
 */
export const dataQueryDirApi = (params: any) => {
  return post(`${PREFIX}data/queryDir`, params);
};

export const dataFileSearchApi = (params: any) => {
  return post(`${PREFIX}data/fileSearch`, params);
};

export const dataDelFileApi = (params: any) => {
  return post(`${PREFIX}data/delFile`, params);
};
export const dataExportKnowledgeListApi = (params: any, filename: string) => {
  return download(`${PREFIX}data/exportKnowledgeList`, params, filename);
};
export const dataDownloadFileApi = (params: any) => {
  return get(`${PREFIX}data/downloadFile`, params);
};

export const getFileBaseInfoApi = (params: any) => {
  return post(`${PREFIX}data/getFileBaseInfo`, params);
};

export const dataUpdateFileApi = (params: any) => {
  return upload(`${PREFIX}data/updateFile`, params);
};

export const fileSearchApi = (params: any) => {
  return post(`${PREFIX}data/fileSearch`, params);
};

/**
 * 获取用户对文件的综合访问权限
 */
export const queryUserFilePermissionApi = (params: any) => {
  return post(`${PREFIX}data/queryPermission`, params);
};
/**
 * 更新用户文件权限信息
 */
export const updateUserFilePermissionApi = (params: any) => {
  return post(`${PREFIX}data/updatePermission`, params);
};

export const getSimulationTaskFilesApi = (params: any) => {
  return post(`${PREFIX}dataAnalysis/getSimulationTaskFile`, params);
};
export const getCSVDataApi = (params: any) => {
  return get(`${PREFIX}dataAnalysis/getCSVData`, params);
};
// 获取文件预览地址
export const getKKFileViewURLFromMinioApi = (params: any) => {
  return get(`${PREFIX}data/getKKFileViewURLFromMinio`, params);
};

/**
 * 获取仿真参数库展示树
 * @param params type 1：模型库/2：模型库分类/3：参数对象 id 传对应模型库id/模型库分类id/参数对象id，不传查所有的模型库
 * @returns
 */
export const getSimulationParameterTreeApi = (params: any) => {
  return get(`${PREFIX}simulationParameterLibrary/getSimulationParameterTree`, params);
};

/**
 * 添加新的仿真参数库
 * @param params parameterLibraryName 仿真参数库名
 * @returns
 */
export const addLibraryApi = (params: any) => {
  return get(`${PREFIX}simulationParameterLibrary/addLibrary`, params);
};

/**
 * 添加新的仿真参数库分类
 * @param params parameterLibraryId 仿真参数库ID parameterLibraryCategoryName 仿真参数库分类名
 * @returns
 */
export const addLibraryCategoryApi = (params: any) => {
  return get(`${PREFIX}simulationParameterLibrary/addLibraryCategory`, params);
};

/**
 * 获取仿真参数库分类参数对象
 * @param params ObjectId 参数对象id
 * @returns
 */
export const getSimulationParameterLibraryCategoryObjectApi = (params: any) => {
  return get(`${PREFIX}simulationParameterLibrary/getSimulationParameterLibraryCategoryObject`, params);
};

/**
 * 添加新的仿真参数库分类的参数对象
 * @param params parameterLibraryId 参数库id parameterLibraryCategoryId 参数分类id parameterLibraryCategoryObjectName 参数对象名 fileName 文件名 file
 * @returns
 */
export const addLibraryCategoryObjectApi = (params: any) => {
  return upload(`${PREFIX}simulationParameterLibrary/addLibraryCategoryObject`, params);
};

/**
 * 删除仿真参数库数据
 * @param params type 1:仿真参数库 2:仿真参数库分类 3:仿真参数库分类参数对象 id 仿真参数库id/仿真参数库分类id/仿真参数库分类参数对象id
 * @returns
 */
export const deleteSimulationParameterApi = (params: any) => {
  return post(`${PREFIX}simulationParameterLibrary/deleteSimulationParameter`, params);
};

/**
 * 查询用户配额
 * @param params
 * @returns
 */
export const listUserQuotaApi = (params: any) => {
  return post(`${PREFIX}dataStorageAnalysis/listUserQuota`, params);
};

/**
 * 新增用户配额
 * @param params
 * @returns
 */
export const addUserQuotaApi = (params: any) => {
  return post(`${PREFIX}dataStorageAnalysis/addUserQuota`, params);
};

/**
 * 批量修改用户配额
 * @param params
 * @returns
 */
export const batchUpdateUserQuotaApi = (params: any) => {
  return post(`${PREFIX}dataStorageAnalysis/batchUpdateUserQuota`, params);
};

/**
 * 存储系统大文件筛选
 * @param params
 * @returns
 */
export const listBigFileApi = (params: any) => {
  return post(`${PREFIX}dataStorageAnalysis/listBigFile`, params);
};

/**
 * 批量删除大文件
 * @param params
 * @returns
 */
export const batchDeleteBigFileApi = (params: any) => {
  return post(`${PREFIX}dataStorageAnalysis/batchDeleteBigFile`, params);
};

/**
 * 根据nodeId(项目nideId)获取指定查询类型文件空间占用
 * @param params
 * @returns
 */
export const getNodeSizeByNodeTypeApi = (params: any) => {
  return get(`${PREFIX}dataStorageAnalysis/getNodeSizeByNodeType`, params);
};

/**
 * 根据用户组和用户id获取用户的空间占用
 * @param params
 * @returns
 */
export const getDirectorySizeByUserIdApi = (params: any) => {
  return get(`${PREFIX}dataStorageAnalysis/getDirectorySizeByUserId`, params);
};

// 分片上传
export const chunkUploadToMinioApi = (params: any) => {
  return upload(`${PREFIX}data/chunkUploadToMinio`, params);
};

// 知识库上传
export const batchAddFileInfoApi = (params: any) => {
  return post(`${PREFIX}data/batchAddFileInfo`, params);
};

// 知识库上传后处理
export const callBackknowledgeFileApi = (params: any) => {
  return post(`${PREFIX}data/callBackknowledgeFile`, params);
};

/**
 * 知识库多文件上传成功回调接口
 * @param params uploadTaskId succBusinessIds failBusinessIds isApprove
 * @returns
 */
export const chunkUploadCallbackApi = (params: any) => {
  return post(`${PREFIX}data/chunkUploadCallback`, params);
};
