import { aql } from 'arangojs' import { ensureGraph, getDb } from '../dist/db.js' type GeoNode = { _key: string node_type: string name: string latitude: number longitude: number country: string country_code: string transport_types?: string[] product_uuid?: string product_name?: string supplier_uuid?: string supplier_name?: string price_per_unit?: string currency?: string quantity?: string unit?: string synced_at: string } async function upsertNode(doc: GeoNode) { const { _key, ...patch } = doc await getDb().query(aql` UPSERT { _key: ${_key} } INSERT ${doc} UPDATE ${patch} IN ${getDb().collection('nodes')} `) } async function upsertEdge(doc: Record) { const key = String(doc._key) const { _key, ...patch } = doc await getDb().query(aql` UPSERT { _key: ${key} } INSERT ${doc} UPDATE ${patch} IN ${getDb().collection('edges')} `) } await ensureGraph() const now = new Date().toISOString() const hubs: GeoNode[] = [ { _key: 'logistics-demo-hub-1', node_type: 'logistics', name: 'Demo Almaty Hub', latitude: 43.238949, longitude: 76.889709, country: 'Kazakhstan', country_code: 'KZ', transport_types: ['AUTO', 'RAIL'], synced_at: now, }, { _key: 'logistics-demo-hub-2', node_type: 'logistics', name: 'Demo Moscow Hub', latitude: 55.755826, longitude: 37.6173, country: 'Russia', country_code: 'RU', transport_types: ['AUTO', 'RAIL'], synced_at: now, }, { _key: 'logistics-demo-hub-3', node_type: 'logistics', name: 'Demo Urumqi Hub', latitude: 43.825592, longitude: 87.616848, country: 'China', country_code: 'CN', transport_types: ['AUTO', 'RAIL'], synced_at: now, }, ] const offers: GeoNode[] = Array.from({ length: 24 }, (_, index) => ({ _key: `geo-demo-offer-${index + 1}`, node_type: 'offer', name: `Demo offer ${index + 1}`, latitude: 43.238949 + (index % 6) * 0.12, longitude: 76.889709 + Math.floor(index / 6) * 0.18, country: index % 3 === 0 ? 'Kazakhstan' : index % 3 === 1 ? 'China' : 'Russia', country_code: index % 3 === 0 ? 'KZ' : index % 3 === 1 ? 'CN' : 'RU', product_uuid: ['55555555-1111-4111-8111-111111111111', '55555555-1111-4111-8111-222222222222', '55555555-1111-4111-8111-333333333333'][index % 3], product_name: ['Copper cathode', 'Aluminum ingot', 'Wheat'][index % 3], supplier_uuid: ['66666666-2222-4111-8111-111111111111', '66666666-2222-4111-8111-222222222222', '66666666-2222-4111-8111-333333333333'][index % 3], supplier_name: ['Demo Supplier Almaty', 'Demo Supplier Urumqi', 'Demo Supplier Moscow'][index % 3], price_per_unit: String(900 + (index % 8) * 55), currency: 'USD', quantity: String(500 + index * 25), unit: 'ton', synced_at: now, })) const suppliers: GeoNode[] = [ { _key: 'geo-demo-supplier-1', node_type: 'supplier', name: 'Demo Supplier Almaty', latitude: 43.25667, longitude: 76.92861, country: 'Kazakhstan', country_code: 'KZ', synced_at: now, }, { _key: 'geo-demo-supplier-2', node_type: 'supplier', name: 'Demo Supplier Urumqi', latitude: 43.825592, longitude: 87.616848, country: 'China', country_code: 'CN', synced_at: now, }, { _key: 'geo-demo-supplier-3', node_type: 'supplier', name: 'Demo Supplier Moscow', latitude: 55.755826, longitude: 37.6173, country: 'Russia', country_code: 'RU', synced_at: now, }, ] for (const node of [...hubs, ...offers, ...suppliers]) { await upsertNode(node) } await upsertEdge({ _key: 'geo-demo-edge-1', _from: 'nodes/logistics-demo-hub-1', _to: 'nodes/logistics-demo-hub-2', to_uuid: 'logistics-demo-hub-2', to_name: 'Demo Moscow Hub', to_latitude: 55.755826, to_longitude: 37.6173, distance_km: 3950, travel_time_seconds: 864000, transport_type: 'rail', }) await upsertEdge({ _key: 'geo-demo-edge-2', _from: 'nodes/logistics-demo-hub-1', _to: 'nodes/logistics-demo-hub-3', to_uuid: 'logistics-demo-hub-3', to_name: 'Demo Urumqi Hub', to_latitude: 43.825592, to_longitude: 87.616848, distance_km: 1050, travel_time_seconds: 172800, transport_type: 'auto', }) console.log(`Seeded geo demo data: hubs ${hubs.length}, offers ${offers.length}, suppliers ${suppliers.length}`)