import { request } from '@umijs/max';
import { InventoryItem, InventoryParams, InventoryList, AdjustInventoryParams, InventoryLogItem } from '@/pages/Inventory/data';

/** 获取库存列表 GET /api/inventory */
export async function queryInventoryList(params: InventoryParams) {
    return request<InventoryList>('/api/inventory', {
        method: 'GET',
        params,
    });
}

/** 新增库存 POST /api/inventory */
export async function addInventory(data: InventoryItem) {
    return request<InventoryItem>('/api/inventory', {
        method: 'POST',
        data,
    });
}

/** 更新库存信息 PUT /api/inventory/:id */
export async function updateInventory(data: Partial<InventoryItem>) {
    return request<InventoryItem>(`/api/inventory/${data.id}`, {
        method: 'PUT',
        data,
    });
}

/** 调整库存（入库/出库/盘点） POST /api/inventory/:id/adjust */
export async function adjustInventory(data: AdjustInventoryParams) {
    return request<{ success: boolean; data: InventoryItem }>(`/api/inventory/${data.id}/adjust`, {
        method: 'POST',
        data,
    });
}


/** 获取库存日志 GET /api/inventory/:id/logs */
export async function queryInventoryLogs(id: string, params?: { current: number, pageSize: number }) {
    return request<{ data: InventoryLogItem[], total: number, success: boolean }>(`/api/inventory/${id}/logs`, {
        method: 'GET',
        params,
    });
}

/** 删除库存 DELETE /api/inventory/:id */
export async function removeInventory(id: string) {
    return request<{ success: boolean }>(`/api/inventory/${id}`, {
        method: 'DELETE',
    });
}
