Skip to main content

csdif_core/
validate.rs

1// SPDX-License-Identifier: MIT
2// Copyright (c) 2025 Egon Kastelijn
3// file: src/validate.rs
4
5use crate::model::CsdifDocument;
6
7/// Validates a CSDIF document for structural consistency.
8pub fn validate_document(doc: &CsdifDocument) -> Result<(), String> {
9    if doc.sensors.is_empty() {
10        return Err("Document must contain at least one sensor.".to_string());
11    }
12
13    for obs in &doc.observations {
14        if !doc.sensors.iter().any(|s| s.id == obs.sensor_id) {
15            return Err(format!("Observation refers to unknown sensor ID: {}", obs.sensor_id));
16        }
17    }
18
19    Ok(())
20}
21