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

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

// 获取文件夹列表
export const dataListDirApi = (params: any) => {
  return get(`${PREFIX}data/listDir`, 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 getKKFileViewURLFromMinioApi = (params: any) => {
  return get(`${PREFIX}data/getKKFileViewURLFromMinio`, 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);
};

// onlyOffice获取文件信息
export const downloadFileForEditApi = (params: any) => {
  return get(`${PREFIX}data/downloadFileForEdit`, params);
};

/**
 * 查询文件树信息
 * @param params
 * @returns
 */
export const dataTreeListDirApi = (params: any) => {
  return get(`${PREFIX}data/listDir?`, params);
};

/**
 * 系统文件下载
 * @param params
 * @returns
 */
export const systemDataDownloadFileApi = (params: any) => {
  return download(`${PREFIX}data/downloadFile`, params);
};

/**
 * 根据节点id查询文件id
 * @param params nodeId 节点的uuid
 * @returns
 */
export const queryFileIdByNodeIdApi = (params: any) => {
  return post(`${PREFIX}data/queryFileIdByNodeId`, params);
};

// 获取minio下载地址
export const getMinioPresignedUrlApi = (params: any) => {
  return get(`${PREFIX}data/getMinioPresignedUrl`, params);
};

export const isDirEmptyApi = (params: any) => {
  return get(`${PREFIX}data/isDirEmpty`, params);
};
