import request from '/@/utils/request';

// 盘点任务查询参数
export interface InventoryCountQueryParams {
	title?: string;
	status?: number;
	countType?: number;
	warehouseId?: string;
	pageNum?: number;
	pageSize?: number;
}

// 盘点任务创建/更新参数
export interface InventoryCountParams {
	id?: string;
	title: string;
	description?: string;
	warehouseId?: string;
	zoneId?: string;
	locationId?: string;
	assetSkuId?: string;
	countType?: number;
	scope?: number;
	plannedStartTime?: string;
	plannedEndTime?: string;
	assigneeId?: string;
	participants?: string[];
	remark?: string;
}

// 获取盘点任务列表
export function listInventoryCounts(params?: InventoryCountQueryParams) {
	return request({
		url: 'assets/inventory/count/listInventoryCounts',
		method: 'get',
		params,
	});
}

// 获取盘点任务详情
export function getInventoryCount(id: string) {
	return request({
		url: 'assets/inventory/count/getInventoryCount',
		method: 'get',
		params: { id },
	});
}

// 创建盘点任务
export function createInventoryCount(data: InventoryCountParams) {
	return request({
		url: 'assets/inventory/count/createInventoryCount',
		method: 'post',
		data,
	});
}

// 更新盘点任务
export function updateInventoryCount(data: InventoryCountParams) {
	return request({
		url: 'assets/inventory/count/updateInventoryCount',
		method: 'put',
		data,
	});
}

// 删除盘点任务
export function deleteInventoryCount(id: string) {
	return request({
		url: 'assets/inventory/count/deleteInventoryCount',
		method: 'delete',
		params: { id },
	});
}

// 完成盘点
export function completeInventoryCount(id: string) {
	return request({
		url: 'assets/inventory/count/completeInventoryCount',
		method: 'post',
		data: { id },
	});
}

// 取消盘点
export function cancelInventoryCount(id: string[], reason?: string) {
	return request({
		url: 'assets/inventory/count/cancelInventoryCount',
		method: 'post',
		data: { id, reason },
	});
}

// 导出盘点
export function exportInventoryCount(id: string) {
	return request({
		url: 'assets/inventory/count/exportInventoryCount',
		method: 'get',
		params: { id },
		responseType: 'blob',
	});
}

// 上传盘点Excel
export function importInventoryCount(id: string, file: File) {
	const formData = new FormData();
	formData.append('id', id);
	formData.append('file', file);
	return request({
		url: 'assets/inventory/count/importInventoryCount',
		method: 'post',
		data: formData,
		headers: {
			'Content-Type': 'multipart/form-data',
		},
	});
}
