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#[allow(unused_imports)]
8use crate::eval::format_validators::*;
9use crate::eval::{ConditionEvaluator, ConditionResult, EvaluationContext};
10
11/// Generated condition evaluator for CONTRL FV2504.
12pub struct ContrlConditionEvaluatorFV2504 {
13    // External condition IDs that require runtime context.
14    external_conditions: std::collections::HashSet<u32>,
15}
16
17impl Default for ContrlConditionEvaluatorFV2504 {
18    fn default() -> Self {
19        let mut external_conditions = std::collections::HashSet::new();
20        external_conditions.insert(1);
21        Self {
22            external_conditions,
23        }
24    }
25}
26
27impl ConditionEvaluator for ContrlConditionEvaluatorFV2504 {
28    fn message_type(&self) -> &str {
29        "CONTRL"
30    }
31
32    fn format_version(&self) -> &str {
33        "FV2504"
34    }
35
36    fn evaluate(&self, condition: u32, ctx: &EvaluationContext) -> ConditionResult {
37        match condition {
38            1 => self.evaluate_1(ctx),
39            2 => self.evaluate_2(ctx),
40            3 => self.evaluate_3(ctx),
41            5 => self.evaluate_5(ctx),
42            6 => self.evaluate_6(ctx),
43            8 => self.evaluate_8(ctx),
44            9 => self.evaluate_9(ctx),
45            _ => ConditionResult::Unknown,
46        }
47    }
48
49    fn is_external(&self, condition: u32) -> bool {
50        self.external_conditions.contains(&condition)
51    }
52    fn is_known(&self, condition: u32) -> bool {
53        matches!(condition, 1 | 2 | 3 | 5 | 6 | 8 | 9)
54    }
55}
56
57impl ContrlConditionEvaluatorFV2504 {
58    /// [1] Wenn Angabe möglich.
59    /// EXTERNAL: Requires context from outside the message.
60    // 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)
61    fn evaluate_1(&self, ctx: &EvaluationContext) -> ConditionResult {
62        ctx.external.evaluate("angabe_moeglich")
63    }
64
65    /// [2] Wenn Syntaxfehler in UNH vorhanden.
66    fn evaluate_2(&self, ctx: &EvaluationContext) -> ConditionResult {
67        let ucm_segments = ctx.find_segments("UCM");
68        ConditionResult::from(ucm_segments.iter().any(|s| {
69            let has_unh = s
70                .elements
71                .get(4)
72                .and_then(|e| e.first())
73                .is_some_and(|v| v == "UNH");
74            let has_error = s
75                .elements
76                .get(3)
77                .and_then(|e| e.first())
78                .is_some_and(|v| !v.is_empty());
79            has_unh && has_error
80        }))
81    }
82
83    /// [3] Wenn Syntaxfehler in UNT vorhanden.
84    fn evaluate_3(&self, ctx: &EvaluationContext) -> ConditionResult {
85        let ucm_segments = ctx.find_segments("UCM");
86        ConditionResult::from(ucm_segments.iter().any(|s| {
87            let has_unt = s
88                .elements
89                .get(4)
90                .and_then(|e| e.first())
91                .is_some_and(|v| v == "UNT");
92            let has_error = s
93                .elements
94                .get(3)
95                .and_then(|e| e.first())
96                .is_some_and(|v| !v.is_empty());
97            has_unt && has_error
98        }))
99    }
100
101    /// [5] Wenn Fehler auf Segment(gruppen)ebene vorhanden.
102    // 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)
103    fn evaluate_5(&self, ctx: &EvaluationContext) -> ConditionResult {
104        let ucm_segments = ctx.find_segments("UCM");
105        ConditionResult::from(ucm_segments.iter().any(|s| {
106            let has_error = s
107                .elements
108                .get(3)
109                .and_then(|e| e.first())
110                .is_some_and(|v| !v.is_empty());
111            // Segment-level error: DE0085 present but S011 (DE0098) absent — no element-level detail
112            let has_element_detail = s
113                .elements
114                .get(5)
115                .and_then(|e| e.first())
116                .is_some_and(|v| !v.is_empty());
117            has_error && !has_element_detail
118        }))
119    }
120
121    /// [6] Wenn Fehler auf Datenelement-, Gruppendatenelement- oder Datengruppenebene vorhanden.
122    // 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)
123    fn evaluate_6(&self, ctx: &EvaluationContext) -> ConditionResult {
124        let ucm_segments = ctx.find_segments("UCM");
125        ConditionResult::from(ucm_segments.iter().any(|s| {
126            // Element-level error: S011 DE0098 (elements[5][0]) is present
127            s.elements
128                .get(5)
129                .and_then(|e| e.first())
130                .is_some_and(|v| !v.is_empty())
131        }))
132    }
133
134    /// [8] Wenn SG1 UCM DE0013 vorhanden.
135    fn evaluate_8(&self, ctx: &EvaluationContext) -> ConditionResult {
136        let ucm_segments = ctx.find_segments("UCM");
137        ConditionResult::from(ucm_segments.iter().any(|s| {
138            s.elements
139                .get(4)
140                .and_then(|e| e.first())
141                .is_some_and(|v| !v.is_empty())
142        }))
143    }
144
145    /// [9] Wenn SG1 UCM DE0013 nicht vorhanden.
146    fn evaluate_9(&self, ctx: &EvaluationContext) -> ConditionResult {
147        let ucm_segments = ctx.find_segments("UCM");
148        if ucm_segments.is_empty() {
149            return ConditionResult::Unknown;
150        }
151        ConditionResult::from(ucm_segments.iter().all(|s| {
152            !s.elements
153                .get(4)
154                .and_then(|e| e.first())
155                .is_some_and(|v| !v.is_empty())
156        }))
157    }
158}