import { apiRequest } from './api'; import type { AssetDataOrigin, AssetInformationStatus, AssetOperationalStatus, PageMeta, } from './api'; export interface InventoryBrowserDepartment { id: string; code: string; name: string; commonName: string | null; type: { id: string; code: string; name: string }; informationStatus: AssetInformationStatus; operationalStatus: AssetOperationalStatus; areaCount: number; childrenCount: number; } export interface InventoryBrowserCompany { id: string; code: string; name: string; commonName: string | null; type: { id: string; code: string; name: string }; informationStatus: AssetInformationStatus; areaCount: number; } export interface InventoryBrowserArea { id: string; code: string; name: string; commonName: string | null; type: { id: string; code: string; name: string }; informationStatus: AssetInformationStatus; operationalStatus: AssetOperationalStatus; currentOperator: { id: string; code: string; name: string } | null; yacimientoCount: number; inventoryCount: number; } export interface InventoryBrowserItem { id: string; code: string; name: string; commonName: string | null; type: { id: string; code: string; name: string }; parent: { id: string; code: string; name: string } | null; informationStatus: AssetInformationStatus; operationalStatus: AssetOperationalStatus; isInventoryInstance: boolean; inventoryFamily: { id: string; code: string; name: string; level: string } | null; childrenCount: number; findingCount: number; hasGeometry: boolean; updatedAt: string; } export interface InventoryListItem { id: string; code: string; name: string; commonName: string | null; type: { id: string; code: string; name: string }; parent: { id: string; code: string; name: string } | null; operationalArea: { id: string; code: string; name: string } | null; operatorCompany: { id: string; code: string; name: string } | null; informationStatus: AssetInformationStatus; operationalStatus: AssetOperationalStatus; childrenCount: number; hasGeometry: boolean; geometryType: string | null; mediaCount: number; dataOrigin: AssetDataOrigin; provenanceVerified: boolean; currentVersion: number; updatedAt: string; } export interface InventoryBrowserParent { id: string; code: string; name: string; typeCode: string; } export interface InventoryQuery { page?: number; pageSize?: number; search?: string; typeId?: string; status?: AssetInformationStatus | ''; operationalStatus?: AssetOperationalStatus | ''; operationalAreaId?: string; operatorCompanyId?: string; needsValidation?: boolean; hasGeometry?: boolean; } function queryString(params: InventoryQuery): string { const query = new URLSearchParams(); Object.entries(params).forEach(([key,value]) => { if (value === undefined || value === null || value === '') return; query.set(key,String(value)); }); return query.size ? `?${query}` : ''; } export function listInventory(params: InventoryQuery = {}) { return apiRequest<{ data: InventoryListItem[]; meta: PageMeta }>( `/inventory-browser/items${queryString(params)}`, ); } // Compatibility alias while old call sites are removed. export const listRealInventory = listInventory; export function listInventoryDepartments(params: InventoryQuery = {}) { return apiRequest<{ data: InventoryBrowserDepartment[]; meta: { count: number } }>( `/inventory-browser/departments${queryString(params)}`, ); } export function listInventoryCompanies(params: InventoryQuery = {}) { return apiRequest<{ data: InventoryBrowserCompany[]; meta: { count: number } }>( `/inventory-browser/companies${queryString(params)}`, ); } export function listInventoryAreas(params: InventoryQuery = {}) { return apiRequest<{ data: InventoryBrowserArea[]; meta: { count: number } }>( `/inventory-browser/areas${queryString(params)}`, ); } export function listInventoryChildren(parentId: string, params: InventoryQuery = {}) { return apiRequest<{ parent: InventoryBrowserParent; data: InventoryBrowserItem[]; meta: { count: number; hasMore: boolean }; }>(`/inventory-browser/${parentId}/children${queryString(params)}`); }