Skip to main content

automapper_validation/generated/fv2504/
contrl_conditions_fv2504.rs

1// <auto-generated>
2// Generated by automapper-generator generate-conditions
3// AHB: xml-migs-and-ahbs/FV2504/CONTRL_AHB_2_4a_Fehlerkorrektur_20250331.xml
4// Generated: 2026-03-12T08:44:40Z
5// </auto-generated>
6
7// LLM-produced bodies aren't idiomatic Rust — silence stylistic lints at
8// file scope so `cargo clippy -D warnings` stays green. Correctness,
9// suspicious, and perf categories stay on so real bugs still surface.
10#![allow(clippy::style, clippy::complexity)]
11
12#[allow(unused_imports)]
13use crate::eval::format_validators::*;
14use crate::eval::{ConditionEvaluator, ConditionResult, EvaluationContext};
15
16/// Generated condition evaluator for CONTRL FV2504.
17pub struct ContrlConditionEvaluatorFV2504 {
18    // External condition IDs that require runtime context.
19    external_conditions: std::collections::HashSet<u32>,
20}
21
22impl Default for ContrlConditionEvaluatorFV2504 {
23    fn default() -> Self {
24        let mut external_conditions = std::collections::HashSet::new();
25        external_conditions.insert(1);
26        Self {
27            external_conditions,
28        }
29    }
30}
31
32impl ConditionEvaluator for ContrlConditionEvaluatorFV2504 {
33    fn message_type(&self) -> &str {
34        "CONTRL"
35    }
36
37    fn format_version(&self) -> &str {
38        "FV2504"
39    }
40
41    fn evaluate(&self, condition: u32, ctx: &EvaluationContext) -> ConditionResult {
42        match condition {
43            1 => self.evaluate_1(ctx),
44            2 => self.evaluate_2(ctx),
45            3 => self.evaluate_3(ctx),
46            5 => self.evaluate_5(ctx),
47            6 => self.evaluate_6(ctx),
48            8 => self.evaluate_8(ctx),
49            9 => self.evaluate_9(ctx),
50            _ => ConditionResult::Unknown,
51        }
52    }
53
54    fn is_external(&self, condition: u32) -> bool {
55        self.external_conditions.contains(&condition)
56    }
57    fn is_known(&self, condition: u32) -> bool {
58        matches!(condition, 1 | 2 | 3 | 5 | 6 | 8 | 9)
59    }
60}
61
62impl ContrlConditionEvaluatorFV2504 {
63    /// [1] Wenn Angabe möglich.
64    /// EXTERNAL: Requires context from outside the message.
65    // REVIEW: "Wenn Angabe möglich" (when specification is possible) is a business-context condition — whether a particular piece of data can be provided depends on external factors (e.g., whether the information is known or available to the sender), not on the content of the EDIFACT message itself. (medium confidence)
66    fn evaluate_1(&self, ctx: &EvaluationContext) -> ConditionResult {
67        ctx.external.evaluate("angabe_moeglich")
68    }
69
70    /// [2] Wenn Syntaxfehler in UNH vorhanden.
71    fn evaluate_2(&self, ctx: &EvaluationContext) -> ConditionResult {
72        let ucm_segments = ctx.find_segments("UCM");
73        ConditionResult::from(ucm_segments.iter().any(|s| {
74            let has_unh = s
75                .elements
76                .get(4)
77                .and_then(|e| e.first())
78                .is_some_and(|v| v == "UNH");
79            let has_error = s
80                .elements
81                .get(3)
82                .and_then(|e| e.first())
83                .is_some_and(|v| !v.is_empty());
84            has_unh && has_error
85        }))
86    }
87
88    /// [3] Wenn Syntaxfehler in UNT vorhanden.
89    fn evaluate_3(&self, ctx: &EvaluationContext) -> ConditionResult {
90        let ucm_segments = ctx.find_segments("UCM");
91        ConditionResult::from(ucm_segments.iter().any(|s| {
92            let has_unt = s
93                .elements
94                .get(4)
95                .and_then(|e| e.first())
96                .is_some_and(|v| v == "UNT");
97            let has_error = s
98                .elements
99                .get(3)
100                .and_then(|e| e.first())
101                .is_some_and(|v| !v.is_empty());
102            has_unt && has_error
103        }))
104    }
105
106    /// [5] Wenn Fehler auf Segment(gruppen)ebene vorhanden.
107    // REVIEW: Segment-group level errors in UCM are identified by DE0085 (syntax error code, elements[3]) being present without S011/DE0098 (element position, elements[5][0]) — meaning the error is at segment level, not pinpointed to a specific data element. (medium confidence)
108    fn evaluate_5(&self, ctx: &EvaluationContext) -> ConditionResult {
109        let ucm_segments = ctx.find_segments("UCM");
110        ConditionResult::from(ucm_segments.iter().any(|s| {
111            let has_error = s
112                .elements
113                .get(3)
114                .and_then(|e| e.first())
115                .is_some_and(|v| !v.is_empty());
116            // Segment-level error: DE0085 present but S011 (DE0098) absent — no element-level detail
117            let has_element_detail = s
118                .elements
119                .get(5)
120                .and_then(|e| e.first())
121                .is_some_and(|v| !v.is_empty());
122            has_error && !has_element_detail
123        }))
124    }
125
126    /// [6] Wenn Fehler auf Datenelement-, Gruppendatenelement- oder Datengruppenebene vorhanden.
127    // REVIEW: Data element / group data element level errors are indicated by S011 being populated. DE0098 (elements[5][0]) holds the segment position of the faulty element. If present, the error is at element level. (medium confidence)
128    fn evaluate_6(&self, ctx: &EvaluationContext) -> ConditionResult {
129        let ucm_segments = ctx.find_segments("UCM");
130        ConditionResult::from(ucm_segments.iter().any(|s| {
131            // Element-level error: S011 DE0098 (elements[5][0]) is present
132            s.elements
133                .get(5)
134                .and_then(|e| e.first())
135                .is_some_and(|v| !v.is_empty())
136        }))
137    }
138
139    /// [8] Wenn SG1 UCM DE0013 vorhanden.
140    fn evaluate_8(&self, ctx: &EvaluationContext) -> ConditionResult {
141        let ucm_segments = ctx.find_segments("UCM");
142        ConditionResult::from(ucm_segments.iter().any(|s| {
143            s.elements
144                .get(4)
145                .and_then(|e| e.first())
146                .is_some_and(|v| !v.is_empty())
147        }))
148    }
149
150    /// [9] Wenn SG1 UCM DE0013 nicht vorhanden.
151    fn evaluate_9(&self, ctx: &EvaluationContext) -> ConditionResult {
152        let ucm_segments = ctx.find_segments("UCM");
153        if ucm_segments.is_empty() {
154            return ConditionResult::Unknown;
155        }
156        ConditionResult::from(ucm_segments.iter().all(|s| {
157            !s.elements
158                .get(4)
159                .and_then(|e| e.first())
160                .is_some_and(|v| !v.is_empty())
161        }))
162    }
163}