/** @format */

import web from "@/utils/axios/web.ts";

/**
 * 获取用户存储商
 * @param data 用户id
 */
export const getAllStorage = (data: any) => {
	return web.request({
		url: "/oss/oss/user/selectUserOSSType",
		method: "get",
		params: {
			userId: data,
		},
	});
};

/**
 * 获取存储商所有存储桶
 * @param data 用户id
 * @param type
 */
export const getStorageBuckets = (data: any, type: any) => {
	return web.request({
		url: "/oss/oss/" + type + "/seleteBucket",
		method: "post",
		params: {
			userId: data,
		},
	});
};
/**
 * 获取存储桶所有文件
 * @param userId
 * @param type
 * @param bucket
 * @param dirName
 */
export const getBucketFiles = (userId: any, bucket: any, dirName: any, type: any) => {
	return web.request({
		url: "/oss/oss/" + type + "/listDir",
		method: "get",
		params: {
			userId: userId,
			bucket: bucket,
			dirName: dirName,
		},
	});
};
/**
 * 获取存储商所有存储桶个数
 * @param userId
 */
export const getStorageAndBuckets = (userId: any) => {
	return web.request({
		url: "/oss/oss/user/selectUserOSSType",
		method: "get",
		params: {
			userId: userId,
		},
	});
};
/**
 * 获取用户文件热力图
 * @param userId
 */
export const getUserFileHeatMap = (userId: any) => {
	return web.request({
		url: "/oss/oss/user/selectUserFileHeat",
		method: "get",
		params: {
			userId: userId,
		},
	});
};
/**
 * 获取用户文件流量
 * @param userId
 */
export const getUserFileFlow = (userId: any) => {
	return web.request({
		url: "/oss/oss/user/selectFileFlow",
		method: "get",
		params: {
			userId: userId,
		},
	});
};
/**
 * 获取用户文件个数
 * @param userId
 */
export const getUserFileCount = (userId: any) => {
	return web.request({
		url: "/oss/oss/user/selectFileCount",
		method: "get",
		params: {
			userId: userId,
		},
	});
};
/**
 * 获取用户每月上传文件个数
 * @param userId
 */
export const getUserUploadFileDiagramPerMonth = (userId: any) => {
	return web.request({
		url: "/oss/oss/user/selectUploadFileDiagramPerMonth",
		method: "get",
		params: {
			userId: userId,
		},
	});
};

/**
 * 获取用户每月下载文件个数
 * @param userId
 */
export const getUserDownloadFileDiagramPerMonth = (userId: any) => {
	return web.request({
		url: "/oss/oss/user/selectDownloadFileDiagramPerMonth",
		method: "get",
		params: {
			userId: userId,
		},
	});
};

/**
 * 获取用户最近下载文件
 * @param userId
 */
export const getUserRecentDownloadFile = (userId: any) => {
	return web.request({
		url: "/oss/oss/user/selectRecentDownloadFile",
		method: "get",
		params: {
			userId: userId,
		},
	});
};
/**
 * 获取用户最近上传文件
 * @param userId
 */
export const getUserRecentUploadFile = (userId: any) => {
	return web.request({
		url: "/oss/oss/user/selectRecentUploadFile",
		method: "get",
		params: {
			userId: userId,
		},
	});
};
/**
 * 获取用户最近预览文件
 * @param userId
 */
export const getUserRecentPreviewFile = (userId: any) => {
	return web.request({
		url: "/oss/oss/user/selectPreviewFile",
		method: "get",
		params: {
			userId: userId,
		},
	});
};
/**
 * 获取存储桶
 * @param userId
 * @param bucket
 * @param type
 */
export const deleteBucket = (userId: any, bucket: any, type: any) => {
	return web.request({
		url: `/oss/oss/` + type + `/deleteBucket`,
		method: "post",
		params: {
			userId: userId,
			bucket: bucket,
		},
	});
};
/**
 * 获取存储桶大小
 * @param userId
 * @param bucket
 * @param type
 */
export const getBucketSize = (userId: any, bucket: any, type: any) => {
	return web.request({
		url: `/oss/oss/` + type + `/getBucketSize`,
		method: "post",
		params: {
			userId: userId,
			bucket: bucket,
		},
	});
};
/**
 * 创建存储桶
 * @param userId
 * @param bucket
 * @param type
 */
export const creatBucket = (userId: any, bucket: any, type: any) => {
	return web.request({
		url: `/oss/oss/` + type + `/createBucket`,
		method: "post",
		params: {
			userId: userId,
			bucket: bucket,
		},
	});
};
/**
 * 删除文件
 * @param userId
 * @param bucket
 * @param type
 * @param filePath
 */
export const deleteFile = (userId: any, bucket: any, type: any, filePath: any) => {
	return web.request({
		url: `/oss/oss/` + type + `/deleteFile`,
		method: "post",
		params: {
			userId: userId,
			bucket: bucket,
			filePath: filePath,
		},
	});
};
/**
 * 下载文件
 * @param userId
 * @param bucket
 * @param type
 * @param listObjectsArgs
 */
export const downloadFiles = (userId: any, bucket: any, type: any, listObjectsArgs: any) => {
	return web.request({
		url: `/oss/oss/` + type + `/downloadFile`,
		method: "get",
		responseType: "blob",
		params: {
			userId: userId,
			bucket: bucket,
			listObjectsArgs: listObjectsArgs,
		},
	});
};
/**
 * 预览文件
 * @param userId
 * @param bucket
 * @param type
 * @param filePath
 */
export const previewFile = (userId: any, bucket: any, type: any, filePath: any) => {
	return web.request({
		url: `/oss/oss/` + type + `/previewFile`,
		method: "post",
		params: {
			userId: userId,
			bucket: bucket,
			filePath: filePath,
		},
	});
};
/**
 * 重命名文件
 * @param userId
 * @param bucket
 * @param type
 * @param oldFileName
 * @param newFileName
 */
export const renameFile = (
	userId: any,
	bucket: any,
	type: any,
	oldFileName: any,
	newFileName: any,
) => {
	return web.request({
		url: `/oss/oss/` + type + `/renameFile`,
		method: "post",
		params: {
			userId: userId,
			bucket: bucket,
			oldFileName: oldFileName,
			newFileName: newFileName,
		},
	});
};
/**
 * 拷贝文件
 * @param userId
 * @param bucket
 * @param type
 * @param oldFilePath
 * @param newFilePath
 */
export const copyFile = (
	userId: any,
	bucket: any,
	type: any,
	oldFilePath: any,
	newFilePath: any,
) => {
	return web.request({
		url: `/oss/oss/` + type + `/copyFile`,
		method: "post",
		params: {
			userId: userId,
			bucket: bucket,
			oldFilePath: oldFilePath,
			newFilePath: newFilePath,
		},
	});
};
/**
 * 创建存储桶
 * @param userId
 * @param bucket
 * @param type
 */
export const createBucket = (userId: any, bucket: any, type: any) => {
	return web.request({
		url: `/oss/oss/` + type + `/createBucket`,
		method: "post",
		params: {
			userId: userId,
			bucket: bucket,
		},
	});
};
/**
 * 上传文件
 * @param type
 * @param data
 * @param peram
 */
export const uploadFiles = (type: any, data: any, peram: any) => {
	return web.request({
		url: `/oss/oss/` + type + `/uploadFile`,
		method: "post",
		headers: {
			"Content-Type": "multipart/form-data",
		},
		data: data,
		params: peram,
	});
};
