automapper_validation/generated/fv2504/
ordchg_conditions_fv2504.rs1#![allow(clippy::style, clippy::complexity)]
11
12#[allow(unused_imports)]
13use crate::eval::format_validators::*;
14use crate::eval::{ConditionEvaluator, ConditionResult, EvaluationContext};
15
16pub struct OrdchgConditionEvaluatorFV2504 {
18 external_conditions: std::collections::HashSet<u32>,
20}
21
22impl Default for OrdchgConditionEvaluatorFV2504 {
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 OrdchgConditionEvaluatorFV2504 {
33 fn message_type(&self) -> &str {
34 "ORDCHG"
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 4 => self.evaluate_4(ctx),
47 5 => self.evaluate_5(ctx),
48 494 => self.evaluate_494(ctx),
49 500 => self.evaluate_500(ctx),
50 501 => self.evaluate_501(ctx),
51 502 => self.evaluate_502(ctx),
52 503 => self.evaluate_503(ctx),
53 931 => self.evaluate_931(ctx),
54 939 => self.evaluate_939(ctx),
55 940 => self.evaluate_940(ctx),
56 _ => ConditionResult::Unknown,
57 }
58 }
59
60 fn is_external(&self, condition: u32) -> bool {
61 self.external_conditions.contains(&condition)
62 }
63 fn is_known(&self, condition: u32) -> bool {
64 matches!(
65 condition,
66 1 | 2 | 3 | 4 | 5 | 494 | 500 | 501 | 502 | 503 | 931 | 939 | 940
67 )
68 }
69}
70
71impl OrdchgConditionEvaluatorFV2504 {
72 fn evaluate_1(&self, ctx: &EvaluationContext) -> ConditionResult {
75 ctx.external.evaluate("mp_id_only_strom")
76 }
77
78 fn evaluate_2(&self, ctx: &EvaluationContext) -> ConditionResult {
80 ctx.has_qualifier("BGM", 0, "Z51")
81 }
82
83 fn evaluate_3(&self, ctx: &EvaluationContext) -> ConditionResult {
85 ctx.has_qualifier("BGM", 0, "Z52")
86 }
87
88 fn evaluate_4(&self, ctx: &EvaluationContext) -> ConditionResult {
90 let coms = ctx.find_segments("COM");
91 ConditionResult::from(coms.iter().any(|com| {
92 com.elements
93 .first()
94 .and_then(|e| e.get(1))
95 .is_some_and(|v| v == "EM")
96 }))
97 }
98
99 fn evaluate_5(&self, ctx: &EvaluationContext) -> ConditionResult {
101 let coms = ctx.find_segments("COM");
102 ConditionResult::from(coms.iter().any(|com| {
103 com.elements
104 .first()
105 .and_then(|e| e.get(1))
106 .is_some_and(|v| matches!(v.as_str(), "TE" | "FX" | "AJ" | "AL"))
107 }))
108 }
109
110 fn evaluate_494(&self, ctx: &EvaluationContext) -> ConditionResult {
112 let current = match ctx.resolved_value {
116 Some(v) if !v.is_empty() => v,
117 _ => return ConditionResult::Unknown,
118 };
119 let threshold = match ctx
120 .find_segments_with_qualifier("DTM", 0, "137")
121 .first()
122 .and_then(|s| s.elements.first())
123 .and_then(|e| e.get(1))
124 {
125 Some(v) if !v.is_empty() => v.clone(),
126 _ => return ConditionResult::Unknown,
127 };
128 ConditionResult::from(current <= threshold.as_str())
129 }
130
131 fn evaluate_500(&self, _ctx: &EvaluationContext) -> ConditionResult {
133 ConditionResult::True
135 }
136
137 fn evaluate_501(&self, _ctx: &EvaluationContext) -> ConditionResult {
139 ConditionResult::True
141 }
142
143 fn evaluate_502(&self, _ctx: &EvaluationContext) -> ConditionResult {
145 ConditionResult::True
147 }
148
149 fn evaluate_503(&self, _ctx: &EvaluationContext) -> ConditionResult {
151 ConditionResult::True
153 }
154
155 fn evaluate_931(&self, ctx: &EvaluationContext) -> ConditionResult {
159 ctx.format_check("DTM", 0, 1, validate_timezone_utc)
160 }
161
162 fn evaluate_939(&self, ctx: &EvaluationContext) -> ConditionResult {
165 let coms = ctx.find_segments("COM");
166 for com in &coms {
167 let is_email = com
168 .elements
169 .first()
170 .and_then(|e| e.get(1))
171 .is_some_and(|v| v == "EM");
172 if is_email {
173 let value = com
174 .elements
175 .first()
176 .and_then(|e| e.first())
177 .cloned()
178 .unwrap_or_default();
179 return ConditionResult::from(value.contains('@') && value.contains('.'));
180 }
181 }
182 ConditionResult::Unknown
183 }
184
185 fn evaluate_940(&self, ctx: &EvaluationContext) -> ConditionResult {
188 let coms = ctx.find_segments("COM");
189 for com in &coms {
190 let is_phone = com
191 .elements
192 .first()
193 .and_then(|e| e.get(1))
194 .is_some_and(|v| matches!(v.as_str(), "TE" | "FX" | "AJ" | "AL"));
195 if is_phone {
196 let value = com
197 .elements
198 .first()
199 .and_then(|e| e.first())
200 .cloned()
201 .unwrap_or_default();
202 let mut chars = value.chars();
203 let starts_with_plus = chars.next() == Some('+');
204 let rest_all_digits = chars.all(|c| c.is_ascii_digit());
205 return ConditionResult::from(starts_with_plus && rest_all_digits);
206 }
207 }
208 ConditionResult::Unknown
209 }
210}