import { newService } from '/@/utils/request';

// 资产列表查询参数
export interface AssetQueryParams {
	name?: string;
	type?: string;
	status?: number;
	page?: number;
	pageSize?: number;
}

// 获取资产列表
export function listAssets(params?: AssetQueryParams) {
	return newService({
		url: '/assets/asset/listAssets',
		method: 'get',
		params,
	});
}

// 更新资产状态
export function updateAssetStatus(id: string, status: number) {
	return newService({
		url: '/assets/asset/updateAssetStatus',
		method: 'put',
		data: { id, status },
	});
}

// 删除资产
export function deleteAsset(id: string) {
	return newService({
		url: '/assets/asset/deleteAsset',
		method: 'delete',
		params: { id },
	});
}

// 获取资产详情
export function getAsset(id: string) {
	return newService({
		url: '/assets/asset/getAsset',
		method: 'get',
		params: { id },
	});
}

// 获取分类选项
export function getAssetCategories() {
	return newService({
		url: '/assets/asset/getAsset',
		method: 'get',
	});
}

// 新增资产
export function createAsset(data: any) {
	return newService({
		url: '/assets/asset/createAsset',
		method: 'post',
		data,
	});
}

// 修改资产
export function updateAsset(data: any) {
	return newService({
		url: '/assets/asset/updateAsset',
		method: 'put',
		data,
	});
}

// 上传资产图片
export function uploadAssetImage(file: File) {
	const formData = new FormData();
	formData.append('file', file);
	return newService({
		url: '/oss/file/uploadFile',
		method: 'post',
		data: formData,
		headers: {
			'Content-Type': 'multipart/form-data',
		},
	});
}

// SKU 列表查询参数
export interface SkuQueryParams {
	assetId: string;
	status?: number;
	keyword?: string;
	minPrice?: number;
	maxPrice?: number;
	page?: number;
	pageSize?: number;
}

// SKU 创建参数
export interface CreateSkuParams {
	assetId: string;
	assetName: string;
	skuName: string;
	imageUrl?: string;
	specValues?: Record<string, any>;
	price: number;
	unlimitedStock: boolean;
	stock: number;
	sort?: number;
	status?: number;
}

// 获取 SKU 列表
export function listAssetSkus(params: SkuQueryParams) {
	return newService({
		url: '/assets/asset/sku/listAssetSkus',
		method: 'get',
		params,
	});
}

// 创建 SKU
export function createAssetSku(data: CreateSkuParams) {
	return newService({
		url: '/assets/asset/sku/createAssetSku',
		method: 'post',
		data,
	});
}

// 获取 SKU 详情
export function getAssetSku(id: string) {
	return newService({
		url: '/assets/asset/sku/getAssetSku',
		method: 'get',
		params: { id },
	});
}

// 修改 SKU
export function updateAssetSku(data: CreateSkuParams & { id: string }) {
	return newService({
		url: '/assets/asset/sku/updateAssetSku',
		method: 'put',
		data,
	});
}

// 删除 SKU
export function deleteAssetSku(id: string) {
	return newService({
		url: '/assets/asset/sku/deleteAssetSku',
		method: 'delete',
		params: { id },
	});
}
