import test from 'node:test'
import assert from 'node:assert/strict'
import { createBimModel } from '../src/facade/bim'

test('BIM hierarchy, material, property and quantity schedule', () => {
  const bim = createBimModel(); bim.addSite({ id: 'site', label: 'Campus', latitude: 40, longitude: -74 }); bim.addBuilding({ id: 'building', label: 'Plant', siteId: 'site' }); bim.addLevel({ id: 'L1', label: 'Ground', elevation: 0, buildingId: 'building' }); bim.addSpace({ id: 'S1', label: 'Plant room', levelId: 'L1', area: 24 }); bim.addMaterial({ id: 'concrete', name: 'Concrete', category: 'structural' }); bim.addElement({ id: 'wall-1', label: 'Wall 1', type: 'wall', shapeId: 'shape-1', levelId: 'L1', spaceId: 'S1', properties: {}, quantity: { length: 5, area: 12, volume: 1.2 } }); bim.assignMaterial('wall-1', 'concrete'); bim.setClassification('wall-1', { system: 'OmniClass', code: '21-02' }); bim.setElementProperty('wall-1', 'FireRating', 'A1'); assert.equal(bim.schedule()[0]?.quantity.volume, 1.2); assert.match(bim.exportIfc(), /IFCBUILDINGELEMENTPROXY/); const ifc = bim.exportIfc('IFC4'); assert.equal(bim.importIfc(ifc).schema, 'IFC4'); assert.equal(bim.importIfc(bim.exportIfc('IFC2X3')).schema, 'IFC2X3')
})

test('BIM rejects elements with missing hierarchy links', () => {
  const bim = createBimModel(); assert.throws(() => bim.addSpace({ id: 'space', label: 'Space', levelId: 'missing' }), /level does not exist/); bim.addLevel({ id: 'L1', label: 'L1', elevation: 0 }); assert.throws(() => bim.addElement({ id: 'wall', label: 'Wall', type: 'wall', shapeId: 'shape', levelId: 'L1', spaceId: 'missing', properties: {}, quantity: {} }), /space does not exist/)
})
