Skip to main content

redispatch_xml/validation/
semantic.rs

1//! Semantic validation — cross-field rules from the BDEW AWT.
2//!
3//! These rules require context from more than one field and cannot be derived
4//! from the XSD alone.
5
6use super::{ValidationError, ValidationResult};
7use crate::documents::activation::ActivationDocType;
8use crate::parse::Document;
9
10/// Run semantic checks on any [`Document`] variant.
11pub fn validate(doc: &Document, result: &mut ValidationResult) {
12    match doc {
13        Document::Activation(d) => {
14            // ACO (A96) and ACR (A41) documents must carry at least one time series.
15            match d.document_type.v {
16                ActivationDocType::RedispatchActivation | ActivationDocType::ActivationResponse => {
17                    if d.time_series.is_empty() {
18                        result.errors.push(ValidationError::Semantic(
19                            "ACO/ACR ActivationDocument must contain at least one ActivationTimeSeries"
20                                .to_string(),
21                        ));
22                    }
23                }
24                // AAR (A42) may have zero time series (tender reduction).
25                ActivationDocType::TenderReduction => {}
26            }
27        }
28        Document::Kostenblatt(d) => {
29            if d.time_series.is_empty() {
30                result.errors.push(ValidationError::Semantic(
31                    "Kostenblatt must contain at least one CostTimeSeries".to_string(),
32                ));
33            }
34        }
35        Document::PlannedResourceSchedule(d) => {
36            if d.time_series.is_empty() {
37                result.errors.push(ValidationError::Semantic(
38                    "PlannedResourceScheduleDocument must contain at least one PlannedResourceTimeSeries"
39                        .to_string(),
40                ));
41            }
42        }
43        // Other document types: no additional semantic rules at this time.
44        _ => {}
45    }
46}