use std::collections::BTreeMap;
use ifc_model::{EntityId, Model};
use ifc_schema::Schema;
use crate::report::{Finding, Path, Report};
pub fn duplicate_global_ids(model: &Model, schema: &Schema, report: &mut Report) {
let mut seen: BTreeMap<&str, Vec<EntityId>> = BTreeMap::new();
for (id, entity) in model.iter() {
if !schema.is_a(&entity.type_name, "IfcRoot") {
continue;
}
let Some(guid) = entity.text(0) else { continue };
seen.entry(guid).or_default().push(id);
}
for (guid, mut holders) in seen {
if holders.len() < 2 {
continue;
}
holders.sort_unstable();
for duplicate in &holders[1..] {
report.push(Finding::error(
"structure.unique.duplicate_global_id",
Path::Entity(*duplicate),
format!("GlobalId {guid} is already used by {}", holders[0]),
));
}
}
}