automapper_validation/generated/fv2510/pricat_conditions_fv2510.rs
1// <auto-generated>
2// Generated by automapper-generator generate-conditions
3// AHB: xml-migs-and-ahbs/FV2510/PRICAT_AHB_2_0f_Fehlerkorrektur_20251211.xml
4// Generated: 2026-03-12T10:50:19Z
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 PRICAT FV2510.
17pub struct PricatConditionEvaluatorFV2510 {
18 // External condition IDs that require runtime context.
19 external_conditions: std::collections::HashSet<u32>,
20}
21
22impl Default for PricatConditionEvaluatorFV2510 {
23 fn default() -> Self {
24 let mut external_conditions = std::collections::HashSet::new();
25 external_conditions.insert(1);
26 external_conditions.insert(8);
27 external_conditions.insert(14);
28 external_conditions.insert(19);
29 external_conditions.insert(22);
30 external_conditions.insert(30);
31 external_conditions.insert(35);
32 external_conditions.insert(36);
33 external_conditions.insert(39);
34 external_conditions.insert(40);
35 external_conditions.insert(41);
36 external_conditions.insert(42);
37 external_conditions.insert(45);
38 external_conditions.insert(46);
39 external_conditions.insert(54);
40 external_conditions.insert(60);
41 external_conditions.insert(63);
42 external_conditions.insert(68);
43 external_conditions.insert(69);
44 external_conditions.insert(70);
45 external_conditions.insert(492);
46 Self {
47 external_conditions,
48 }
49 }
50}
51
52impl ConditionEvaluator for PricatConditionEvaluatorFV2510 {
53 fn message_type(&self) -> &str {
54 "PRICAT"
55 }
56
57 fn format_version(&self) -> &str {
58 "FV2510"
59 }
60
61 fn evaluate(&self, condition: u32, ctx: &EvaluationContext) -> ConditionResult {
62 match condition {
63 1 => self.evaluate_1(ctx),
64 2 => self.evaluate_2(ctx),
65 3 => self.evaluate_3(ctx),
66 4 => self.evaluate_4(ctx),
67 5 => self.evaluate_5(ctx),
68 6 => self.evaluate_6(ctx),
69 7 => self.evaluate_7(ctx),
70 8 => self.evaluate_8(ctx),
71 9 => self.evaluate_9(ctx),
72 10 => self.evaluate_10(ctx),
73 12 => self.evaluate_12(ctx),
74 14 => self.evaluate_14(ctx),
75 19 => self.evaluate_19(ctx),
76 22 => self.evaluate_22(ctx),
77 24 => self.evaluate_24(ctx),
78 26 => self.evaluate_26(ctx),
79 27 => self.evaluate_27(ctx),
80 28 => self.evaluate_28(ctx),
81 29 => self.evaluate_29(ctx),
82 30 => self.evaluate_30(ctx),
83 31 => self.evaluate_31(ctx),
84 32 => self.evaluate_32(ctx),
85 33 => self.evaluate_33(ctx),
86 34 => self.evaluate_34(ctx),
87 35 => self.evaluate_35(ctx),
88 36 => self.evaluate_36(ctx),
89 37 => self.evaluate_37(ctx),
90 38 => self.evaluate_38(ctx),
91 39 => self.evaluate_39(ctx),
92 40 => self.evaluate_40(ctx),
93 41 => self.evaluate_41(ctx),
94 42 => self.evaluate_42(ctx),
95 43 => self.evaluate_43(ctx),
96 44 => self.evaluate_44(ctx),
97 45 => self.evaluate_45(ctx),
98 46 => self.evaluate_46(ctx),
99 47 => self.evaluate_47(ctx),
100 48 => self.evaluate_48(ctx),
101 49 => self.evaluate_49(ctx),
102 50 => self.evaluate_50(ctx),
103 51 => self.evaluate_51(ctx),
104 52 => self.evaluate_52(ctx),
105 53 => self.evaluate_53(ctx),
106 54 => self.evaluate_54(ctx),
107 55 => self.evaluate_55(ctx),
108 56 => self.evaluate_56(ctx),
109 57 => self.evaluate_57(ctx),
110 60 => self.evaluate_60(ctx),
111 61 => self.evaluate_61(ctx),
112 62 => self.evaluate_62(ctx),
113 63 => self.evaluate_63(ctx),
114 64 => self.evaluate_64(ctx),
115 65 => self.evaluate_65(ctx),
116 66 => self.evaluate_66(ctx),
117 67 => self.evaluate_67(ctx),
118 68 => self.evaluate_68(ctx),
119 69 => self.evaluate_69(ctx),
120 70 => self.evaluate_70(ctx),
121 71 => self.evaluate_71(ctx),
122 72 => self.evaluate_72(ctx),
123 490 => self.evaluate_490(ctx),
124 491 => self.evaluate_491(ctx),
125 492 => self.evaluate_492(ctx),
126 494 => self.evaluate_494(ctx),
127 495 => self.evaluate_495(ctx),
128 502 => self.evaluate_502(ctx),
129 503 => self.evaluate_503(ctx),
130 504 => self.evaluate_504(ctx),
131 511 => self.evaluate_511(ctx),
132 512 => self.evaluate_512(ctx),
133 513 => self.evaluate_513(ctx),
134 519 => self.evaluate_519(ctx),
135 520 => self.evaluate_520(ctx),
136 521 => self.evaluate_521(ctx),
137 522 => self.evaluate_522(ctx),
138 902 => self.evaluate_902(ctx),
139 908 => self.evaluate_908(ctx),
140 909 => self.evaluate_909(ctx),
141 911 => self.evaluate_911(ctx),
142 912 => self.evaluate_912(ctx),
143 926 => self.evaluate_926(ctx),
144 929 => self.evaluate_929(ctx),
145 931 => self.evaluate_931(ctx),
146 932 => self.evaluate_932(ctx),
147 933 => self.evaluate_933(ctx),
148 937 => self.evaluate_937(ctx),
149 939 => self.evaluate_939(ctx),
150 940 => self.evaluate_940(ctx),
151 941 => self.evaluate_941(ctx),
152 942 => self.evaluate_942(ctx),
153 946 => self.evaluate_946(ctx),
154 948 => self.evaluate_948(ctx),
155 949 => self.evaluate_949(ctx),
156 957 => self.evaluate_957(ctx),
157 959 => self.evaluate_959(ctx),
158 968 => self.evaluate_968(ctx),
159 _ => ConditionResult::Unknown,
160 }
161 }
162
163 fn is_external(&self, condition: u32) -> bool {
164 self.external_conditions.contains(&condition)
165 }
166 fn is_known(&self, condition: u32) -> bool {
167 matches!(
168 condition,
169 1 | 2
170 | 3
171 | 4
172 | 5
173 | 6
174 | 7
175 | 8
176 | 9
177 | 10
178 | 12
179 | 14
180 | 19
181 | 22
182 | 24
183 | 26
184 | 27
185 | 28
186 | 29
187 | 30
188 | 31
189 | 32
190 | 33
191 | 34
192 | 35
193 | 36
194 | 37
195 | 38
196 | 39
197 | 40
198 | 41
199 | 42
200 | 43
201 | 44
202 | 45
203 | 46
204 | 47
205 | 48
206 | 49
207 | 50
208 | 51
209 | 52
210 | 53
211 | 54
212 | 55
213 | 56
214 | 57
215 | 60
216 | 61
217 | 62
218 | 63
219 | 64
220 | 65
221 | 66
222 | 67
223 | 68
224 | 69
225 | 70
226 | 71
227 | 72
228 | 490
229 | 491
230 | 492
231 | 494
232 | 495
233 | 502
234 | 503
235 | 504
236 | 511
237 | 512
238 | 513
239 | 519
240 | 520
241 | 521
242 | 522
243 | 902
244 | 908
245 | 909
246 | 911
247 | 912
248 | 926
249 | 929
250 | 931
251 | 932
252 | 933
253 | 937
254 | 939
255 | 940
256 | 941
257 | 942
258 | 946
259 | 948
260 | 949
261 | 957
262 | 959
263 | 968
264 )
265 }
266}
267
268impl PricatConditionEvaluatorFV2510 {
269 /// [8] Wenn das in DE1001 angegebene Preisblatt vom NB nicht genutzt wird.
270 /// EXTERNAL: Requires context from outside the message.
271 fn evaluate_8(&self, ctx: &EvaluationContext) -> ConditionResult {
272 ctx.external.evaluate("nb_does_not_use_price_list")
273 }
274
275 /// [10] Wenn eine weitere SG36 vorhanden ist, bei der sich der Inhalt von LIN DE7140 von LIN DE7140 dieser SG36 nur in der Ziffer nach dem letzten "-" unterscheidet und die Ziffer dort größer ist als in ...
276 // REVIEW: Requires iterating all SG36 instances, extracting LIN DE7140 (elements[2][0]), splitting on the last '-', and checking whether any other SG36 has the same prefix with a strictly higher numeric suffix. This is the 'Gruppenartikel-ID / Artikel-ID' relationship. Group path SG17→SG36 based on PRICAT tx_group='SG17' from project knowledge. (medium confidence)
277 fn evaluate_10(&self, ctx: &EvaluationContext) -> ConditionResult {
278 // HAND-EDITED: "eine weitere SG36 … nur in der Ziffer nach dem letzten "-" … größer" — compared with the other instances when the
279 // scope reaches an SG36; the message as before otherwise.
280 if let Some(scope) = ctx.enclosing_scope("SG36") {
281 let Some((prefix, number)) = article_at(ctx, scope) else {
282 return ConditionResult::False;
283 };
284 return ConditionResult::from(all_articles(ctx).iter().any(|p| {
285 p.as_slice() != scope
286 && article_at(ctx, p).is_some_and(|(q, n)| q == prefix && n > number)
287 }));
288 }
289 let nav = match ctx.navigator() {
290 Some(n) => n,
291 None => return ConditionResult::Unknown,
292 };
293 let sg36_count = nav.group_instance_count(&["SG17", "SG36"]);
294 if sg36_count < 2 {
295 return ConditionResult::False;
296 }
297 // Collect all LIN DE7140 values from SG36 instances (elements[2][0])
298 let mut lin_values: Vec<String> = Vec::new();
299 for i in 0..sg36_count {
300 let lin_segs = nav.find_segments_in_group("LIN", &["SG17", "SG36"], i);
301 let val = lin_segs
302 .first()
303 .and_then(|s| s.elements.get(2))
304 .and_then(|e| e.first())
305 .cloned()
306 .unwrap_or_default();
307 lin_values.push(val);
308 }
309 // Check if any pair shares the prefix before the last '-'
310 // with one having a strictly higher numeric suffix
311 for i in 0..lin_values.len() {
312 let a = &lin_values[i];
313 if a.is_empty() {
314 continue;
315 }
316 let Some(pos_a) = a.rfind('-') else {
317 continue;
318 };
319 let prefix_a = &a[..pos_a];
320 let Ok(num_a) = a[pos_a + 1..].parse::<u64>() else {
321 continue;
322 };
323 for j in 0..lin_values.len() {
324 if i == j {
325 continue;
326 }
327 let b = &lin_values[j];
328 if b.is_empty() {
329 continue;
330 }
331 let Some(pos_b) = b.rfind('-') else {
332 continue;
333 };
334 let prefix_b = &b[..pos_b];
335 let Ok(num_b) = b[pos_b + 1..].parse::<u64>() else {
336 continue;
337 };
338 if prefix_a == prefix_b && num_b > num_a {
339 return ConditionResult::True;
340 }
341 }
342 }
343 ConditionResult::False
344 }
345
346 /// [31] wenn BGM DE1001 = Z32 (Preisblatt Messstellenbetrieb)
347 fn evaluate_31(&self, ctx: &EvaluationContext) -> ConditionResult {
348 ctx.has_segment_matching("BGM", &[(0, 0, "Z32")])
349 }
350
351 /// [34] wenn BGM DE1001 = Z77 (Preisblatt Konfigurationen)
352 fn evaluate_34(&self, ctx: &EvaluationContext) -> ConditionResult {
353 ctx.has_segment_matching("BGM", &[(0, 0, "Z77")])
354 }
355
356 /// [35] Wenn das in DE1001 angegebene Preisblatt vom MSB nicht genutzt wird.
357 /// EXTERNAL: Requires context from outside the message.
358 fn evaluate_35(&self, ctx: &EvaluationContext) -> ConditionResult {
359 ctx.external.evaluate("msb_does_not_use_price_list")
360 }
361
362 /// [44] Wenn BGM DE1001 = Z77, dann muss der hier genannte Zeitpunkt ≥ 01.10.2023 00:00 Uhr gesetzlicher deutscher Zeit sein
363 // REVIEW: Checks BGM DE1001 == Z77, then validates DTM+137 (document date) >= 2023-10-01 00:00. 'Der hier genannte Zeitpunkt' refers to the timestamp field where this condition is annotated in the AHB; DTM+137 is assumed as the document date for PRICAT. Condition is inapplicable (Unknown) when BGM code is not Z77. German legal time threshold mapped to 202310010000 using dtm_ge string comparison on format 303. (medium confidence)
364 fn evaluate_44(&self, ctx: &EvaluationContext) -> ConditionResult {
365 let bgm_segs = ctx.find_segments("BGM");
366 let is_z77 = bgm_segs
367 .first()
368 .and_then(|s| s.elements.first())
369 .and_then(|e| e.first())
370 .is_some_and(|v| v == "Z77");
371 if !is_z77 {
372 return ConditionResult::Unknown;
373 }
374 ctx.dtm_ge("137", "202310010000")
375 }
376
377 /// [45] Es sind nur Werte aus der EDI@Energy Codeliste der Artikelnummern und Artikel-ID erlaubt, die in dieser in Kapitel "Abrechnung Messstellenbetrieb für die Sparte Strom" für die jeweilige Marktroll...
378 /// EXTERNAL: Requires context from outside the message.
379 fn evaluate_45(&self, ctx: &EvaluationContext) -> ConditionResult {
380 ctx.external.evaluate("artikel_messstellenbetrieb_strom")
381 }
382
383 /// [46] Es sind nur Werte aus der EDI@Energy Codeliste der Artikelnummern und Artikel-ID erlaubt, die in dieser in Kapitel "Artikel-ID für die Bestellprozesse beim MSB" genannt sind
384 /// EXTERNAL: Requires context from outside the message.
385 fn evaluate_46(&self, ctx: &EvaluationContext) -> ConditionResult {
386 ctx.external.evaluate("artikel_bestellprozesse_msb")
387 }
388
389 /// [55] Wenn in dieser SG36 ein weiteres RNG (d. h. eine weitere Zone) vorhanden ist, in der der Wert des DE6162 (Wertebereichsgrenze, untere) größer ist als der Wert des DE6162 in diesem RNG
390 // REVIEW: Each SG36 represents one price zone (one RNG). Collects DE6162 (lower range boundary) from RNG elements[1][1] (C280 component 1 = lower bound) across all SG36 instances under SG17. Condition is True if any zone has a strictly higher lower bound than another (min < max), meaning there exists a zone with higher DE6162 than the current minimum. Returns False if fewer than 2 zones or all lower bounds are equal. Group path SG17.SG36 follows PRICAT tx_group=SG17 convention. (medium confidence)
391 fn evaluate_55(&self, ctx: &EvaluationContext) -> ConditionResult {
392 // HAND-EDITED: "in dieser SG36 ein weiteres RNG … DE6162 größer als … in diesem RNG" — compared with the other instances when the
393 // scope reaches an SG40; the message as before otherwise.
394 if let Some(scope) = ctx.enclosing_scope("SG40") {
395 let Some(own) = zones_at(ctx, scope).first().and_then(|z| z.0) else {
396 return ConditionResult::Unknown;
397 };
398 let zones = ctx.scopes_under("SG36", "SG40").unwrap_or_default();
399 return ConditionResult::from(zones.iter().any(|p| {
400 p.as_slice() != scope
401 && zones_at(ctx, p)
402 .iter()
403 .any(|z| z.0.is_some_and(|lower| lower > own))
404 }));
405 }
406 let nav = match ctx.navigator() {
407 Some(n) => n,
408 None => return ConditionResult::Unknown,
409 };
410 let sg36_count = nav.group_instance_count(&["SG17", "SG36"]);
411 let mut lower_bounds: Vec<f64> = Vec::new();
412 for i in 0..sg36_count {
413 let rng_segs = nav.find_segments_in_group("RNG", &["SG17", "SG36"], i);
414 for rng in &rng_segs {
415 // C280: [0]=unit, [1]=DE6162 lower bound, [2]=DE6163 upper bound
416 if let Some(val) = rng.elements.get(1).and_then(|e| e.get(1)) {
417 if let Ok(n) = val.parse::<f64>() {
418 lower_bounds.push(n);
419 }
420 }
421 }
422 }
423 if lower_bounds.len() < 2 {
424 return ConditionResult::False;
425 }
426 let min_val = lower_bounds.iter().cloned().fold(f64::INFINITY, f64::min);
427 ConditionResult::from(lower_bounds.iter().any(|&v| v > min_val))
428 }
429
430 /// [56] Wenn BGM DE1001 = Z94, dann muss der hier genannte Zeitpunkt ≥ 01.10.2025 00:00 Uhr gesetzlicher deutscher Zeit sein
431 // REVIEW: Checks BGM DE1001 == Z94, then validates DTM+137 (document date) >= 2025-10-01 00:00. Mirrors condition 44 pattern but for the Z94 document code introduced with FV2510 and the later threshold date. Condition is inapplicable (Unknown) when BGM code is not Z94. German legal time threshold 2025-10-01 00:00 mapped to 202510010000. (medium confidence)
432 fn evaluate_56(&self, ctx: &EvaluationContext) -> ConditionResult {
433 let bgm_segs = ctx.find_segments("BGM");
434 let is_z94 = bgm_segs
435 .first()
436 .and_then(|s| s.elements.first())
437 .and_then(|e| e.first())
438 .is_some_and(|v| v == "Z94");
439 if !is_z94 {
440 return ConditionResult::Unknown;
441 }
442 ctx.dtm_ge("137", "202510010000")
443 }
444
445 /// [57] wenn BGM DE1001 = Z94 (Preisblatt Technik)
446 fn evaluate_57(&self, ctx: &EvaluationContext) -> ConditionResult {
447 ctx.has_qualifier("BGM", 0, "Z94")
448 }
449
450 /// [60] Wenn in dieser SG36 der Teil vor dem "-" aus LIN DE7140 aus der Tabelle des Kapitels "Produkte zur Bestellung einer Änderung an einer Lokation in der Sparte Strom" der EDI@Energy Codeliste der Kon...
451 /// EXTERNAL: Requires context from outside the message.
452 fn evaluate_60(&self, ctx: &EvaluationContext) -> ConditionResult {
453 ctx.external
454 .evaluate("lin_product_code_is_lokationsaenderung_strom")
455 }
456
457 /// [61] Wenn in dieser SG36 der Wert der Zahl nach dem "-" aus LIN DE7140 > 01
458 // REVIEW: LIN DE7140 is elements[2][0]. The condition checks if the numeric part after '-' is greater than 01 (i.e., > 1). Uses group-scoped navigator for SG36 instances, falls back to message-wide on no navigator. Parses after the dash and compares as u32. (medium confidence)
459 fn evaluate_61(&self, ctx: &EvaluationContext) -> ConditionResult {
460 // HAND-EDITED: "in dieser SG36 der Wert der Zahl nach dem '-' aus LIN DE7140 > 01" — the enclosing SG36 only, when the scope
461 // reaches one; the message as before otherwise.
462 if let Some(scope) = ctx.enclosing_scope("SG36") {
463 return ConditionResult::from(ctx.find_segments_at(scope, "LIN").iter().any(|s| {
464 s.get_component(2, 0)
465 .split_once('-')
466 .and_then(|(_, n)| n.parse::<u32>().ok())
467 .is_some_and(|n| n > 1)
468 }));
469 }
470 let nav = match ctx.navigator() {
471 Some(n) => n,
472 None => {
473 let lin_segs = ctx.find_segments("LIN");
474 for lin in &lin_segs {
475 if let Some(val) = lin.elements.get(2).and_then(|e| e.first()) {
476 if let Some(after_dash) = val.splitn(2, '-').nth(1) {
477 if let Ok(num) = after_dash.parse::<u32>() {
478 if num > 1 {
479 return ConditionResult::True;
480 }
481 }
482 }
483 }
484 }
485 return ConditionResult::False;
486 }
487 };
488 let sg36_count = nav.group_instance_count(&["SG36"]);
489 for i in 0..sg36_count {
490 let lin_segs = nav.find_segments_in_group("LIN", &["SG36"], i);
491 for lin in &lin_segs {
492 if let Some(val) = lin.elements.get(2).and_then(|e| e.first()) {
493 if let Some(after_dash) = val.splitn(2, '-').nth(1) {
494 if let Ok(num) = after_dash.parse::<u32>() {
495 if num > 1 {
496 return ConditionResult::True;
497 }
498 }
499 }
500 }
501 }
502 }
503 ConditionResult::False
504 }
505
506 /// [62] Wenn IMD+F vorhanden
507 fn evaluate_62(&self, ctx: &EvaluationContext) -> ConditionResult {
508 ctx.has_qualifier("IMD", 0, "F")
509 }
510
511 /// [63] Wenn vorheriges DE7008 zur Beschreibung der Leistung dieser Artikel-ID nicht ausreicht
512 /// EXTERNAL: Requires context from outside the message.
513 fn evaluate_63(&self, ctx: &EvaluationContext) -> ConditionResult {
514 ctx.external
515 .evaluate("previous_imd_description_insufficient")
516 }
517
518 /// [65] wenn in dieser SG36 der Teil des Codes in LIN DE7140 nach dem "-" von "01" abweicht
519 // REVIEW: Checks if the part of LIN DE7140 (elements[2][0]) after '-' differs from '01'. Iterates SG36 instances via navigator; falls back to message-wide LIN scan. Returns True if any SG36 contains a LIN where the suffix is not '01'. (medium confidence)
520 fn evaluate_65(&self, ctx: &EvaluationContext) -> ConditionResult {
521 // HAND-EDITED: "in dieser SG36 der Teil des Codes in LIN DE7140 nach dem '-' von '01' abweicht" — the enclosing SG36 only, when the scope
522 // reaches one; the message as before otherwise.
523 if let Some(scope) = ctx.enclosing_scope("SG36") {
524 return ConditionResult::from(ctx.find_segments_at(scope, "LIN").iter().any(|s| {
525 s.get_component(2, 0)
526 .split_once('-')
527 .is_some_and(|(_, n)| n != "01")
528 }));
529 }
530 let nav = match ctx.navigator() {
531 Some(n) => n,
532 None => {
533 let lins = ctx.find_segments("LIN");
534 let found = lins.iter().any(|s| {
535 s.elements
536 .get(2)
537 .and_then(|e| e.first())
538 .and_then(|code| code.split_once('-'))
539 .map(|(_, suffix)| suffix != "01")
540 .unwrap_or(false)
541 });
542 return ConditionResult::from(found);
543 }
544 };
545 let sg36_count = nav.group_instance_count(&["SG17", "SG36"]);
546 for i in 0..sg36_count {
547 let lins = nav.find_segments_in_group("LIN", &["SG17", "SG36"], i);
548 for lin in &lins {
549 if let Some(code) = lin.elements.get(2).and_then(|e| e.first()) {
550 if code
551 .split_once('-')
552 .map(|(_, suffix)| suffix != "01")
553 .unwrap_or(false)
554 {
555 return ConditionResult::True;
556 }
557 }
558 }
559 }
560 ConditionResult::False
561 }
562
563 /// [66] wenn im DE7140 des LIN dieser SG36 der Teil des Codes nach dem "-" den Wert 02 hat, muss dieses DE = 0 sein und in allen anderen RNG zu Artikel-ID, bei denen der Teil des Codes vor dem "-" mit dem ...
564 // REVIEW: Two-part check on RNG DE6162 (lower bound) for SG36 instances whose LIN DE7140 has the suffix "02": (1) the current "02"-SG36's DE6162 must equal "0"; (2) every other SG36 sharing the LIN prefix must have its DE6162 match some other matching-prefix SG36's DE6152 (upper bound) — i.e., a chain-continuity check. RNG sits in child group SG40 under SG36; DE6162 = elements[1][1], DE6152 = elements[1][2] (same positions used in the already-working [72]).
565 fn evaluate_66(&self, ctx: &EvaluationContext) -> ConditionResult {
566 // HAND-EDITED: "nach dem "-" 02 → dieses DE = 0; sonst = DE6152 eines anderen RNG derselben Gruppenartikel-ID" — compared with the other instances when the
567 // scope reaches an SG40; the message as before otherwise.
568 if let Some(scope) = ctx.enclosing_scope("SG40") {
569 let (Some(sg36), Some(own)) = (
570 ctx.enclosing_scope("SG36"),
571 zones_at(ctx, scope).first().and_then(|z| z.0),
572 ) else {
573 return ConditionResult::Unknown;
574 };
575 let Some((prefix, number)) = article_at(ctx, sg36) else {
576 return ConditionResult::Unknown;
577 };
578 if number == 2 {
579 return ConditionResult::from(own == 0.0);
580 }
581 // The other zones of every Artikel-ID of this Gruppenartikel-ID.
582 let matches = all_articles(ctx).iter().any(|p| {
583 article_at(ctx, p).is_some_and(|(q, _)| q == prefix)
584 && zone_paths(ctx, p)
585 .iter()
586 .filter(|z| z.as_slice() != scope)
587 .any(|z| zones_at(ctx, z).iter().any(|r| r.1 == Some(own)))
588 });
589 return ConditionResult::from(matches);
590 }
591 let nav = match ctx.navigator() {
592 Some(n) => n,
593 None => return ConditionResult::Unknown,
594 };
595 let sg36_count = nav.group_instance_count(&["SG36"]);
596 if sg36_count == 0 {
597 return ConditionResult::Unknown;
598 }
599
600 struct Sg36 {
601 prefix: String,
602 suffix: String,
603 lower: Option<String>,
604 upper: Option<String>,
605 }
606
607 let collected: Vec<Sg36> = (0..sg36_count)
608 .map(|i| {
609 let lin_val = nav
610 .find_segments_in_group("LIN", &["SG36"], i)
611 .first()
612 .and_then(|s| s.elements.get(2))
613 .and_then(|e| e.first())
614 .cloned()
615 .unwrap_or_default();
616 let (prefix, suffix) = lin_val
617 .split_once('-')
618 .map(|(p, s)| (p.to_string(), s.to_string()))
619 .unwrap_or_default();
620 let sg40_count = nav.child_group_instance_count(&["SG36"], i, "SG40");
621 let mut lower: Option<String> = None;
622 let mut upper: Option<String> = None;
623 for j in 0..sg40_count {
624 let rngs = nav.find_segments_in_child_group("RNG", &["SG36"], i, "SG40", j);
625 if let Some(rng) = rngs.first() {
626 if lower.is_none() {
627 lower = rng
628 .elements
629 .get(1)
630 .and_then(|e| e.get(1))
631 .filter(|v| !v.is_empty())
632 .cloned();
633 }
634 if upper.is_none() {
635 upper = rng
636 .elements
637 .get(1)
638 .and_then(|e| e.get(2))
639 .filter(|v| !v.is_empty())
640 .cloned();
641 }
642 }
643 if lower.is_some() && upper.is_some() {
644 break;
645 }
646 }
647 Sg36 {
648 prefix,
649 suffix,
650 lower,
651 upper,
652 }
653 })
654 .collect();
655
656 // No trigger ("02"-suffix SG36) in the message → condition does not apply.
657 if !collected.iter().any(|s| s.suffix == "02") {
658 return ConditionResult::Unknown;
659 }
660
661 for (t_idx, trigger) in collected
662 .iter()
663 .enumerate()
664 .filter(|(_, s)| s.suffix == "02")
665 {
666 // (1) The trigger's own lower bound must be "0".
667 match &trigger.lower {
668 Some(v) if v == "0" => {}
669 _ => return ConditionResult::False,
670 }
671 // (2) Every OTHER matching-prefix SG36's lower bound must equal
672 // some DIFFERENT matching-prefix SG36's upper bound.
673 let matching: Vec<(usize, &Sg36)> = collected
674 .iter()
675 .enumerate()
676 .filter(|(_, s)| s.prefix == trigger.prefix)
677 .collect();
678 for (o_idx, other) in &matching {
679 if *o_idx == t_idx {
680 continue;
681 }
682 let lower = match &other.lower {
683 Some(v) => v.as_str(),
684 None => return ConditionResult::False,
685 };
686 let found_chain = matching
687 .iter()
688 .filter(|(x_idx, _)| *x_idx != *o_idx)
689 .any(|(_, x)| x.upper.as_deref() == Some(lower));
690 if !found_chain {
691 return ConditionResult::False;
692 }
693 }
694 }
695 ConditionResult::True
696 }
697
698 /// [67] wenn in dieser SG17 ein weiteres LIN vorhanden ist, in dem der Teil des Codes vor dem "-" des DE7140 mit dem des DE7140 des LIN dieser SG36 identisch ist und in dem der Wert nach dem "-" um eins gr...
699 // REVIEW: Iterates all SG17 instances and collects (prefix, suffix) pairs from LIN DE7140 across all their child SG36 instances. For each code, checks whether another LIN in the same SG17 has the same prefix and a numerically incremented suffix (preserving leading-zero width). Returns True if such a consecutive pair exists. (medium confidence)
700 fn evaluate_67(&self, ctx: &EvaluationContext) -> ConditionResult {
701 // HAND-EDITED: "in dieser SG17 ein weiteres LIN … vor dem "-" identisch … um eins größer" — compared with the other instances when the
702 // scope reaches an SG36; the message as before otherwise.
703 if let Some(scope) = ctx.enclosing_scope("SG36") {
704 let Some((prefix, number)) = article_at(ctx, scope) else {
705 return ConditionResult::False;
706 };
707 let sg36s = ctx.scopes_under("SG17", "SG36").unwrap_or_default();
708 return ConditionResult::from(sg36s.iter().any(|p| {
709 p.as_slice() != scope
710 && article_at(ctx, p).is_some_and(|(q, n)| q == prefix && n == number + 1)
711 }));
712 }
713 let nav = match ctx.navigator() {
714 Some(n) => n,
715 None => return ConditionResult::Unknown,
716 };
717 let sg17_count = nav.group_instance_count(&["SG17"]);
718 for sg17_i in 0..sg17_count {
719 let sg36_count = nav.child_group_instance_count(&["SG17"], sg17_i, "SG36");
720 let mut code_parts: Vec<(String, String)> = Vec::new();
721 for sg36_i in 0..sg36_count {
722 let lins =
723 nav.find_segments_in_child_group("LIN", &["SG17"], sg17_i, "SG36", sg36_i);
724 for lin in &lins {
725 if let Some(code) = lin.elements.get(2).and_then(|e| e.first()) {
726 if let Some((prefix, suffix)) = code.split_once('-') {
727 code_parts.push((prefix.to_string(), suffix.to_string()));
728 }
729 }
730 }
731 }
732 for (prefix, suffix) in &code_parts {
733 if let Ok(n) = suffix.parse::<u32>() {
734 let next = n + 1;
735 let width = suffix.len();
736 let next_str = format!("{:0width$}", next, width = width);
737 if code_parts
738 .iter()
739 .any(|(p, s)| p == prefix && s == &next_str)
740 {
741 return ConditionResult::True;
742 }
743 }
744 }
745 }
746 ConditionResult::False
747 }
748
749 /// [68] Der Teil des Codes vor dem "-" muss ein Messprodukt-Code sein
750 /// EXTERNAL: Requires context from outside the message.
751 fn evaluate_68(&self, ctx: &EvaluationContext) -> ConditionResult {
752 ctx.external.evaluate("is_messprodukt_code")
753 }
754
755 /// [69] Der Teil des Codes vor dem "-" muss ein Konfigurationsprodukt-Code sein
756 /// EXTERNAL: Requires context from outside the message.
757 fn evaluate_69(&self, ctx: &EvaluationContext) -> ConditionResult {
758 ctx.external.evaluate("is_konfigurationsprodukt_code")
759 }
760
761 /// [70] Der Teil des Codes vor dem "-" muss ein Produkt-Code sein
762 /// EXTERNAL: Requires context from outside the message.
763 fn evaluate_70(&self, ctx: &EvaluationContext) -> ConditionResult {
764 ctx.external.evaluate("lin_prefix_is_valid_product_code")
765 }
766
767 /// [71] Es muss der Code 9991000003030-01 sein
768 fn evaluate_71(&self, ctx: &EvaluationContext) -> ConditionResult {
769 let segs = ctx.find_segments("LIN");
770 if segs.is_empty() {
771 return ConditionResult::Unknown;
772 }
773 let matches = segs.iter().any(|s| {
774 s.elements
775 .get(2)
776 .and_then(|e| e.first())
777 .is_some_and(|v| v == "9991000003030-01")
778 });
779 ConditionResult::from(matches)
780 }
781
782 /// [72] Wenn in dieser SG36 die letzte Ziffer von LIN DE7140 >1 ist, dann muss es eine SG36 geben dessen Inhalt von LIN DE7140 sich von dem in dieser SG36 nur in der letzten Ziffer unterscheidet und in ...
783 // REVIEW: Cross-SG36 interval continuity check: for each SG36 whose LIN DE7140 ends with digit > 1, there must be another SG36 with DE7140 differing only in the last digit, and that SG36's RNG DE6152 (upper bound, elements[1][2]) must equal this SG36's RNG DE6162 (lower bound, elements[1][1]). RNG is in child group SG40 under SG36. Implemented via navigator with parent-child navigation. Medium confidence due to complexity of cross-group interval continuity logic. (medium confidence)
784 fn evaluate_72(&self, ctx: &EvaluationContext) -> ConditionResult {
785 // HAND-EDITED: "letzte Ziffer von LIN DE7140 >1 → eine SG36 … deren RNG DE6152 = dieses DE6162" — compared with the other instances when the
786 // scope reaches an SG40; the message as before otherwise.
787 if let Some(scope) = ctx.enclosing_scope("SG40") {
788 let (Some(sg36), Some(own)) = (
789 ctx.enclosing_scope("SG36"),
790 zones_at(ctx, scope).first().and_then(|z| z.0),
791 ) else {
792 return ConditionResult::Unknown;
793 };
794 let Some((prefix, number)) = article_at(ctx, sg36) else {
795 return ConditionResult::Unknown;
796 };
797 if number <= 1 {
798 return ConditionResult::True;
799 }
800 return ConditionResult::from(all_articles(ctx).iter().any(|p| {
801 p.as_slice() != sg36
802 && article_at(ctx, p).is_some_and(|(q, _)| q == prefix)
803 && zones_at(ctx, p).iter().any(|r| r.1 == Some(own))
804 }));
805 }
806 let nav = match ctx.navigator() {
807 Some(n) => n,
808 None => return ConditionResult::Unknown,
809 };
810 let sg36_count = nav.group_instance_count(&["SG36"]);
811 if sg36_count == 0 {
812 return ConditionResult::Unknown;
813 }
814 for i in 0..sg36_count {
815 let lin_segs = nav.find_segments_in_group("LIN", &["SG36"], i);
816 let lin_val = match lin_segs
817 .first()
818 .and_then(|s| s.elements.get(2))
819 .and_then(|e| e.first())
820 .filter(|v| !v.is_empty())
821 {
822 Some(v) => v.clone(),
823 None => continue,
824 };
825 let last_digit = match lin_val.chars().last().and_then(|c| c.to_digit(10)) {
826 Some(d) => d,
827 None => continue,
828 };
829 if last_digit <= 1 {
830 continue;
831 }
832 // Get this SG36's RNG DE6162 (lower bound) from child SG40
833 let sg40_count = nav.child_group_instance_count(&["SG36"], i, "SG40");
834 let mut this_lower: Option<String> = None;
835 for j in 0..sg40_count {
836 let rngs = nav.find_segments_in_child_group("RNG", &["SG36"], i, "SG40", j);
837 if let Some(rng) = rngs.first() {
838 if let Some(lower) = rng.elements.get(1).and_then(|e| e.get(1)) {
839 if !lower.is_empty() {
840 this_lower = Some(lower.clone());
841 break;
842 }
843 }
844 }
845 }
846 let this_lower = match this_lower {
847 Some(v) => v,
848 None => continue,
849 };
850 let lin_prefix = &lin_val[..lin_val.len() - 1];
851 let mut found = false;
852 for k in 0..sg36_count {
853 if k == i {
854 continue;
855 }
856 let lin_segs_k = nav.find_segments_in_group("LIN", &["SG36"], k);
857 let lin_val_k = match lin_segs_k
858 .first()
859 .and_then(|s| s.elements.get(2))
860 .and_then(|e| e.first())
861 .filter(|v| !v.is_empty())
862 {
863 Some(v) => v.clone(),
864 None => continue,
865 };
866 if lin_val_k.len() != lin_val.len() {
867 continue;
868 }
869 if &lin_val_k[..lin_val_k.len() - 1] != lin_prefix {
870 continue;
871 }
872 // Check RNG DE6152 (upper bound) in that SG36's SG40
873 let sg40_count_k = nav.child_group_instance_count(&["SG36"], k, "SG40");
874 for j in 0..sg40_count_k {
875 let rngs_k = nav.find_segments_in_child_group("RNG", &["SG36"], k, "SG40", j);
876 if let Some(rng_k) = rngs_k.first() {
877 if let Some(upper_k) = rng_k.elements.get(1).and_then(|e| e.get(2)) {
878 if upper_k == &this_lower {
879 found = true;
880 break;
881 }
882 }
883 }
884 }
885 if found {
886 break;
887 }
888 }
889 if !found {
890 return ConditionResult::False;
891 }
892 }
893 ConditionResult::True
894 }
895
896 /// [511] Hinweis: 1. Der genannte Wert gehört nicht zum Intervall. 2. Die untere Wertegrenze zu der Artikel-ID, deren Zahl an der letzten Stelle den Wert n hat, muss kleiner sein, als die untere Wertegren...
897 fn evaluate_511(&self, _ctx: &EvaluationContext) -> ConditionResult {
898 // Hinweis: 1. Der genannte Wert gehört nicht zum Intervall.
899 // 2. Die untere Wertegrenze zu der Artikel-ID, deren Zahl an der letzten Stelle den Wert n hat,
900 // muss kleiner sein, als die untere Wertegrenze zu der Artikel-ID, deren Zahl an der letzten
901 // Stelle den Wert n+1 hat. — informational annotation, always applies
902 ConditionResult::True
903 }
904
905 /// [522] Hinweis: Hier ist die Leistung zu beschreiben, die mit dieser Artikel-ID in Rechnung gestellt wird, wobei darauf zu achten ist, dass zu erkennen ist, wie sich diese von den Leistungen unterscheiden...
906 fn evaluate_522(&self, _ctx: &EvaluationContext) -> ConditionResult {
907 // Hinweis: Hier ist die Leistung zu beschreiben, die mit dieser Artikel-ID in Rechnung gestellt
908 // wird, wobei darauf zu achten ist, dass zu erkennen ist, wie sich diese von den Leistungen
909 // unterscheiden, bei denen die ersten 13 Stellen der Artikel-ID mit den ersten 13 Stellen
910 // dieser Artikel-ID identisch sind. — informational annotation, always applies
911 ConditionResult::True
912 }
913
914 /// [1] Wenn Vorgängerversion vorhanden
915 /// EXTERNAL: Requires context from outside the message.
916 // REVIEW: Whether a Vorgängerversion (predecessor version) exists is a business context question — it depends on whether a prior PRICAT was sent for the same catalog/articles and is tracked outside the EDIFACT message itself. Cannot be determined from the current message content alone. (medium confidence)
917 fn evaluate_1(&self, ctx: &EvaluationContext) -> ConditionResult {
918 ctx.external.evaluate("previous_version_exists")
919 }
920
921 /// [2] Wenn in dieser SG36 LIN in DE7140 9990001000813 vorhanden
922 fn evaluate_2(&self, ctx: &EvaluationContext) -> ConditionResult {
923 // HAND-EDITED: "in dieser/derselben SG36" — scoped to the enclosing group.
924 let values = ctx.this_group_values("LIN", 2, 0, &["SG36"]);
925 ConditionResult::from(values.iter().any(|(_, v)| v == "9990001000813"))
926 }
927
928 /// [3] Wenn IMD+X vorhanden
929 fn evaluate_3(&self, ctx: &EvaluationContext) -> ConditionResult {
930 ctx.has_qualifier("IMD", 0, "X")
931 }
932
933 /// [4] Wenn SG36 IMD+C in diesem IMD vorhanden
934 fn evaluate_4(&self, ctx: &EvaluationContext) -> ConditionResult {
935 ctx.any_group_has_qualifier("IMD", 0, "C", &["SG36"])
936 }
937
938 /// [5] Wenn SG36 IMD+X in diesem IMD vorhanden
939 fn evaluate_5(&self, ctx: &EvaluationContext) -> ConditionResult {
940 ctx.any_group_has_qualifier("IMD", 0, "X", &["SG36"])
941 }
942
943 /// [6] Wenn in dieser SG36 LIN in DE7140 9990001000798 vorhanden
944 fn evaluate_6(&self, ctx: &EvaluationContext) -> ConditionResult {
945 // HAND-EDITED: "in dieser/derselben SG36" — scoped to the enclosing group.
946 let values = ctx.this_group_values("LIN", 2, 0, &["SG36"]);
947 ConditionResult::from(values.iter().any(|(_, v)| v == "9990001000798"))
948 }
949
950 /// [7] Wenn in dieser SG36 LIN in DE7140 9990001000798 nicht vorhanden
951 fn evaluate_7(&self, ctx: &EvaluationContext) -> ConditionResult {
952 // HAND-EDITED: "in dieser/derselben SG36" — scoped to the enclosing group.
953 let values = ctx.this_group_values("LIN", 2, 0, &["SG36"]);
954 ConditionResult::from(!values.iter().any(|(_, v)| v == "9990001000798"))
955 }
956
957 /// [9] Wenn BGM DE1373 =11 nicht vorhanden
958 fn evaluate_9(&self, ctx: &EvaluationContext) -> ConditionResult {
959 match ctx.find_segment("BGM") {
960 None => ConditionResult::False, // segment absent → condition not applicable
961 Some(seg) => {
962 let val = seg
963 .elements
964 .get(4)
965 .and_then(|e| e.first())
966 .map(|s| s.as_str())
967 .unwrap_or("");
968 ConditionResult::from(val != "11")
969 }
970 }
971 }
972
973 /// [12] je UNB ist nur eine Nachricht mit BGM+Z04 in der Übertragungsdatei erlaubt (nur eine Nachricht je Übertragungsdatei)
974 // REVIEW: The notation-resolved hint says elements[0]=Z04. BGM C002.DE1001 is at elements[0][0]. has_qualifier checks elements[0][0]=='Z04'. The 'only one per UNB' structural constraint is an AHB rule consuming this condition — within a single message, we can only check if this IS a Z04 message type. (medium confidence)
975 fn evaluate_12(&self, ctx: &EvaluationContext) -> ConditionResult {
976 ctx.has_qualifier("BGM", 0, "Z04")
977 }
978
979 /// [14] je UNB ist maximal je Code aus DE1001 eine Nachricht in der Übertragungsdatei erlaubt
980 /// EXTERNAL: Requires context from outside the message.
981 // REVIEW: This is a transmission-level cardinality constraint: per UNB envelope, at most one message per DE1001 message type code is allowed. Enforcing this requires visibility into all messages within the same UNB envelope, which is outside the scope of evaluating a single message's EvaluationContext. Must be handled externally at the interchange/envelope level. (medium confidence)
982 fn evaluate_14(&self, ctx: &EvaluationContext) -> ConditionResult {
983 ctx.external.evaluate("max_one_message_per_type_in_unb")
984 }
985
986 /// [19] Nur MP-ID aus Sparte Strom
987 /// EXTERNAL: Requires context from outside the message.
988 // REVIEW: Nur MP-ID aus Sparte Strom — checking whether a market participant ID belongs to the electricity (Strom) sector requires a lookup against an external market participant registry (Marktstammdatenregister or similar). The sector classification cannot be derived from the EDIFACT message content alone. (medium confidence)
989 fn evaluate_19(&self, ctx: &EvaluationContext) -> ConditionResult {
990 ctx.external.evaluate("mp_id_is_strom_sector")
991 }
992
993 /// [22] Wenn die Artikel-ID aus dieser SG36 LIN DE7140 in der EDI@Energy Codeliste der Artikelnummern und Artikel-ID in der Spalte "PRICAT Preisangabe" ein X hat
994 /// EXTERNAL: Requires context from outside the message.
995 // REVIEW: This condition requires a lookup of the Artikel-ID from LIN DE7140 (elements[2][0]) against the EDI@Energy code list of article numbers, specifically checking whether the 'PRICAT Preisangabe' column has an X for that entry. Code list membership checks against external EDI@Energy publications cannot be determined from EDIFACT message content alone — they require an external code list resolver. (medium confidence)
996 fn evaluate_22(&self, ctx: &EvaluationContext) -> ConditionResult {
997 ctx.external.evaluate("article_id_has_pricat_price_flag")
998 }
999
1000 /// [24] Wenn in dieser SG36 Wert von LIN DE7140 im Format n1-n2-n1-n8-n2-n1
1001 fn evaluate_24(&self, ctx: &EvaluationContext) -> ConditionResult {
1002 // HAND-EDITED: "in dieser/derselben SG36" — scoped to the enclosing group.
1003 let values = ctx.this_group_values("LIN", 2, 0, &["SG36"]);
1004 ConditionResult::from(values.iter().any(|(_, val)| {
1005 let parts: Vec<&str> = val.split('-').collect();
1006 if parts.len() != 6 {
1007 return false;
1008 }
1009 let expected_lens = [1usize, 2, 1, 8, 2, 1];
1010 parts
1011 .iter()
1012 .zip(expected_lens.iter())
1013 .all(|(p, &len)| p.len() == len && p.chars().all(|ch| ch.is_ascii_digit()))
1014 }))
1015 }
1016
1017 /// [26] Wenn BGM DE1001 = Z70 vorhanden
1018 fn evaluate_26(&self, ctx: &EvaluationContext) -> ConditionResult {
1019 ctx.has_qualifier("BGM", 0, "Z70")
1020 }
1021
1022 /// [27] Wenn BGM DE1001 = Z70 nicht vorhanden
1023 fn evaluate_27(&self, ctx: &EvaluationContext) -> ConditionResult {
1024 ctx.lacks_qualifier("BGM", 0, "Z70")
1025 }
1026
1027 /// [28] Wenn die zugehörige Artikel-ID in der letzten Stelle eine 1 ist
1028 // REVIEW: Checks the last character of the article ID (Artikel-ID) in the PIA segment. The PIA segment's additional product identification is at elements[1][0]. Last digit '1' → True, any other digit → False. Medium confidence because the exact PIA element path for Artikel-ID in PRICAT is assumed from convention; no segment structure reference provided. (medium confidence)
1029 fn evaluate_28(&self, ctx: &EvaluationContext) -> ConditionResult {
1030 // Wenn die zugehörige Artikel-ID in der letzten Stelle eine 1 ist
1031 // Artikel-ID is in PIA segment, elements[1][0]
1032 let segs = ctx.find_segments("PIA");
1033 match segs
1034 .first()
1035 .and_then(|s| s.elements.get(1))
1036 .and_then(|e| e.first())
1037 {
1038 Some(val) => match val.chars().last() {
1039 Some('1') => ConditionResult::True,
1040 Some(c) if c.is_ascii_digit() => ConditionResult::False,
1041 Some(_) => ConditionResult::False,
1042 None => ConditionResult::False, // segment absent → condition not applicable
1043 },
1044 None => ConditionResult::False, // segment absent → condition not applicable
1045 }
1046 }
1047
1048 /// [29] Wenn die zugehörige Artikel-ID in der letzten Stelle > 1 ist
1049 // REVIEW: Checks the last character of the article ID in PIA elements[1][0]. Last digit > '1' (i.e., '2'–'9') → True, last digit <= '1' → False. Same assumptions as condition 28 regarding PIA element path. (medium confidence)
1050 fn evaluate_29(&self, ctx: &EvaluationContext) -> ConditionResult {
1051 // Wenn die zugehörige Artikel-ID in der letzten Stelle > 1 ist
1052 // Artikel-ID is in PIA segment, elements[1][0]
1053 let segs = ctx.find_segments("PIA");
1054 match segs
1055 .first()
1056 .and_then(|s| s.elements.get(1))
1057 .and_then(|e| e.first())
1058 {
1059 Some(val) => match val.chars().last() {
1060 Some(c) if c.is_ascii_digit() && c > '1' => ConditionResult::True,
1061 Some(c) if c.is_ascii_digit() => ConditionResult::False,
1062 Some(_) => ConditionResult::False,
1063 None => ConditionResult::False, // segment absent → condition not applicable
1064 },
1065 None => ConditionResult::False, // segment absent → condition not applicable
1066 }
1067 }
1068
1069 /// [30] wenn MP-ID in SG2 NAD+MR in der Rolle LF
1070 /// EXTERNAL: Requires context from outside the message.
1071 fn evaluate_30(&self, ctx: &EvaluationContext) -> ConditionResult {
1072 ctx.external.evaluate("recipient_is_lf")
1073 }
1074
1075 /// [32] wenn der Zeitpunkt im DTM+157 DE2380 < 01.01.2024 00:00 Uhr gesetzlicher deutscher Zeit
1076 // REVIEW: DTM+157 (Gültigkeitsbeginn) has DE2380 at elements[0][1] in format 303 (YYYYMMDDHHMM). String comparison is valid for this zero-padded numeric format. Assumes German local time encoding as per EDI@Energy convention. Returns Unknown if DTM+157 is absent. (medium confidence)
1077 fn evaluate_32(&self, ctx: &EvaluationContext) -> ConditionResult {
1078 {
1079 let dtms = ctx.find_segments_with_qualifier("DTM", 0, "157");
1080 match dtms.first() {
1081 Some(dtm) => {
1082 match dtm
1083 .elements
1084 .first()
1085 .and_then(|e| e.get(1))
1086 .map(|s| s.as_str())
1087 {
1088 Some(value) if !value.is_empty() => {
1089 // Format 303: YYYYMMDDHHMM — string comparison valid for numeric date strings
1090 // 01.01.2024 00:00 German legal time → "202401010000"
1091 ConditionResult::from(value < "202401010000")
1092 }
1093 _ => ConditionResult::Unknown,
1094 }
1095 }
1096 None => ConditionResult::False, // segment absent → condition not applicable
1097 }
1098 }
1099 }
1100
1101 /// [33] wenn der Zeitpunkt im DTM+157 DE2380 ≥ 01.01.2024 00:00 Uhr gesetzlicher deutscher Zeit
1102 // REVIEW: Mirror of condition 32 with >= comparison. DTM+157 DE2380 at elements[0][1], format 303. Returns Unknown if segment absent. (medium confidence)
1103 fn evaluate_33(&self, ctx: &EvaluationContext) -> ConditionResult {
1104 {
1105 let dtms = ctx.find_segments_with_qualifier("DTM", 0, "157");
1106 match dtms.first() {
1107 Some(dtm) => {
1108 match dtm
1109 .elements
1110 .first()
1111 .and_then(|e| e.get(1))
1112 .map(|s| s.as_str())
1113 {
1114 Some(value) if !value.is_empty() => {
1115 // Format 303: YYYYMMDDHHMM — string comparison valid for numeric date strings
1116 // 01.01.2024 00:00 German legal time → "202401010000"
1117 ConditionResult::from(value >= "202401010000")
1118 }
1119 _ => ConditionResult::Unknown,
1120 }
1121 }
1122 None => ConditionResult::False, // segment absent → condition not applicable
1123 }
1124 }
1125 }
1126
1127 /// [36] Wenn MP-ID in SG2 NAD+MR in der Rolle NB
1128 /// EXTERNAL: Requires context from outside the message.
1129 fn evaluate_36(&self, ctx: &EvaluationContext) -> ConditionResult {
1130 ctx.external.evaluate("recipient_is_nb")
1131 }
1132
1133 /// [37] Wenn im DE3155 in demselben COM der Code EM vorhanden ist
1134 // REVIEW: COM segment C076 has DE3148 (number) at elements[0][0] and DE3155 (channel code) at elements[0][1]. The condition checks if DE3155 == "EM" (email). COM segment structure is standard EDIFACT and not ambiguous despite not being in the provided reference. 'Demselben COM' at message level means any COM with EM qualifier. (medium confidence)
1135 fn evaluate_37(&self, ctx: &EvaluationContext) -> ConditionResult {
1136 {
1137 let coms = ctx.find_segments("COM");
1138 ConditionResult::from(coms.iter().any(|s| {
1139 s.elements
1140 .first()
1141 .and_then(|e| e.get(1))
1142 .is_some_and(|v| v == "EM")
1143 }))
1144 }
1145 }
1146
1147 /// [38] Wenn im DE3155 in demselben COM der Code TE / FX / AJ / AL vorhanden ist
1148 // REVIEW: Same COM segment structure as condition 37. Checks DE3155 for any of TE (telephone), FX (fax), AJ, AL channel codes. (medium confidence)
1149 fn evaluate_38(&self, ctx: &EvaluationContext) -> ConditionResult {
1150 {
1151 let coms = ctx.find_segments("COM");
1152 ConditionResult::from(coms.iter().any(|s| {
1153 s.elements
1154 .first()
1155 .and_then(|e| e.get(1))
1156 .is_some_and(|v| matches!(v.as_str(), "TE" | "FX" | "AJ" | "AL"))
1157 }))
1158 }
1159 }
1160
1161 /// [39] Es sind nur Werte aus der EDI@Energy Codeliste der Artikelnummern und Artikel-ID erlaubt, die in der Spalte MaBiS ein X haben
1162 /// EXTERNAL: Requires context from outside the message.
1163 fn evaluate_39(&self, ctx: &EvaluationContext) -> ConditionResult {
1164 ctx.external.evaluate("article_id_in_mabis_codelist")
1165 }
1166
1167 /// [40] Es sind nur Werte aus der EDI@Energy Codeliste der Artikelnummern und Artikel-ID erlaubt, die in der Spalte H ein X haben
1168 /// EXTERNAL: Requires context from outside the message.
1169 fn evaluate_40(&self, ctx: &EvaluationContext) -> ConditionResult {
1170 ctx.external.evaluate("article_id_in_h_codelist")
1171 }
1172
1173 /// [41] Es sind nur Werte aus der EDI@Energy Codeliste der Artikelnummern und Artikel-ID erlaubt, die in der Spalte "PRICAT Codeverwendung" ein X haben
1174 /// EXTERNAL: Requires context from outside the message.
1175 fn evaluate_41(&self, ctx: &EvaluationContext) -> ConditionResult {
1176 ctx.external.evaluate("article_id_in_pricat_codelist")
1177 }
1178
1179 /// [42] Es sind nur Werte erlaubt, die die Bildungsvorschrift der EDI@Energy Codeliste der Artikelnummern und Artikel-ID erfüllen, und die in der Spalte "PRICAT Codeverwendung" ein X haben
1180 /// EXTERNAL: Requires context from outside the message.
1181 fn evaluate_42(&self, ctx: &EvaluationContext) -> ConditionResult {
1182 ctx.external
1183 .evaluate("article_id_valid_pricat_formation_rule")
1184 }
1185
1186 /// [43] Wenn BGM DE1001 = Z32 und LIN DE7140 im Format n1-n2-n1-n3, dann muss der hier genannte Zeitpunkt ≥ 01.01.2024 00:00 Uhr gesetzlicher deutscher Zeit sein
1187 // REVIEW: Checks BGM DE1001==Z32, LIN DE7140 contains hyphens (n1-n2-n1-n3 format like '1-01-6-005'), and DTM+157 (Gültigkeitsbeginn) >= 20240101. Medium confidence because 'der hier genannte Zeitpunkt' is assumed to be DTM+157. (medium confidence)
1188 fn evaluate_43(&self, ctx: &EvaluationContext) -> ConditionResult {
1189 let bgm = match ctx.find_segment("BGM") {
1190 Some(s) => s,
1191 None => return ConditionResult::Unknown,
1192 };
1193 if bgm
1194 .elements
1195 .first()
1196 .and_then(|e| e.first())
1197 .map(|s| s.as_str())
1198 != Some("Z32")
1199 {
1200 return ConditionResult::False;
1201 }
1202 let lin_segments = ctx.find_segments("LIN");
1203 let has_hyphen_format = lin_segments.iter().any(|s| {
1204 s.elements
1205 .get(2)
1206 .and_then(|e| e.first())
1207 .map_or(false, |v| v.contains('-'))
1208 });
1209 if !has_hyphen_format {
1210 return ConditionResult::False;
1211 }
1212 let dtm_segs = ctx.find_segments_with_qualifier("DTM", 0, "157");
1213 match dtm_segs.first() {
1214 Some(dtm) => {
1215 let value = dtm
1216 .elements
1217 .first()
1218 .and_then(|e| e.get(1))
1219 .map(|s| s.as_str())
1220 .unwrap_or("");
1221 if value.len() >= 8 {
1222 ConditionResult::from(&value[..8] >= "20240101")
1223 } else {
1224 ConditionResult::Unknown
1225 }
1226 }
1227 None => ConditionResult::False, // segment absent → condition not applicable
1228 }
1229 }
1230
1231 /// [47] Wenn BGM DE1001 = Z32 und LIN DE7140 im Format n13, dann muss der hier genannte Zeitpunkt < 01.01.2024 00:00 Uhr gesetzlicher deutscher Zeit sein
1232 // REVIEW: Checks BGM DE1001==Z32, LIN DE7140 is exactly 13 digits with no hyphens (legacy EAN/GLN format), and DTM+157 < 20240101. Complement of condition 43. (medium confidence)
1233 fn evaluate_47(&self, ctx: &EvaluationContext) -> ConditionResult {
1234 let bgm = match ctx.find_segment("BGM") {
1235 Some(s) => s,
1236 None => return ConditionResult::Unknown,
1237 };
1238 if bgm
1239 .elements
1240 .first()
1241 .and_then(|e| e.first())
1242 .map(|s| s.as_str())
1243 != Some("Z32")
1244 {
1245 return ConditionResult::False;
1246 }
1247 let lin_segments = ctx.find_segments("LIN");
1248 let has_n13_format = lin_segments.iter().any(|s| {
1249 s.elements
1250 .get(2)
1251 .and_then(|e| e.first())
1252 .map_or(false, |v| {
1253 !v.contains('-') && v.len() == 13 && v.chars().all(|c| c.is_ascii_digit())
1254 })
1255 });
1256 if !has_n13_format {
1257 return ConditionResult::False;
1258 }
1259 let dtm_segs = ctx.find_segments_with_qualifier("DTM", 0, "157");
1260 match dtm_segs.first() {
1261 Some(dtm) => {
1262 let value = dtm
1263 .elements
1264 .first()
1265 .and_then(|e| e.get(1))
1266 .map(|s| s.as_str())
1267 .unwrap_or("");
1268 if value.len() >= 8 {
1269 ConditionResult::from(&value[..8] < "20240101")
1270 } else {
1271 ConditionResult::Unknown
1272 }
1273 }
1274 None => ConditionResult::False, // segment absent → condition not applicable
1275 }
1276 }
1277
1278 /// [48] Wenn in dieser SG36 LIN in DE7140 einer der Codes 1-01-6-005 / 1-01-9-001 / 1-01-9-002 / 1-02-0-015 / 1-03-8-001 / 1-03-8-002 / 1-03-8-003 / 1-03-8-004 / 1-03-9-001 / 1-03-9-002 / 1-03-9-003 / 1-03...
1279 fn evaluate_48(&self, ctx: &EvaluationContext) -> ConditionResult {
1280 // HAND-EDITED: "in dieser/derselben SG36" — scoped to the enclosing group.
1281 const CODES: &[&str] = &[
1282 "1-01-6-005",
1283 "1-01-9-001",
1284 "1-01-9-002",
1285 "1-02-0-015",
1286 "1-03-8-001",
1287 "1-03-8-002",
1288 "1-03-8-003",
1289 "1-03-8-004",
1290 "1-03-9-001",
1291 "1-03-9-002",
1292 "1-03-9-003",
1293 "1-03-9-004",
1294 "1-07-4-001",
1295 ];
1296 let lin_segments = ctx.scoped_find_segments_in("SG36", "LIN");
1297 ConditionResult::from(lin_segments.iter().any(|s| {
1298 s.elements
1299 .get(2)
1300 .and_then(|e| e.first())
1301 .map_or(false, |v| CODES.contains(&v.as_str()))
1302 }))
1303 }
1304
1305 /// [49] Wenn in dieser SG36 LIN in DE7140 keiner der Codes 1-01-6-005 / 1-01-9-001 / 1-01-9-002 / 1-02-0-015 / 1-03-8-001 / 1-03-8-002 / 1-03-8-003 / 1-03-8-004 / 1-03-9-001 / 1-03-9-002 / 1-03-9-003 / 1-0...
1306 fn evaluate_49(&self, ctx: &EvaluationContext) -> ConditionResult {
1307 // HAND-EDITED: "in dieser/derselben SG36" — scoped to the enclosing group.
1308 const CODES: &[&str] = &[
1309 "1-01-6-005",
1310 "1-01-9-001",
1311 "1-01-9-002",
1312 "1-02-0-015",
1313 "1-03-8-001",
1314 "1-03-8-002",
1315 "1-03-8-003",
1316 "1-03-8-004",
1317 "1-03-9-001",
1318 "1-03-9-002",
1319 "1-03-9-003",
1320 "1-03-9-004",
1321 "1-07-4-001",
1322 ];
1323 let lin_segments = ctx.scoped_find_segments_in("SG36", "LIN");
1324 ConditionResult::from(!lin_segments.iter().any(|s| {
1325 s.elements
1326 .get(2)
1327 .and_then(|e| e.first())
1328 .map_or(false, |v| CODES.contains(&v.as_str()))
1329 }))
1330 }
1331
1332 /// [50] Wenn MP-ID aus RFF+Z56 mit MP-ID aus NAD+MS identisch ist
1333 fn evaluate_50(&self, ctx: &EvaluationContext) -> ConditionResult {
1334 let rff_segs = ctx.find_segments_with_qualifier("RFF", 0, "Z56");
1335 let nad_segs = ctx.find_segments_with_qualifier("NAD", 0, "MS");
1336 let rff_mp_id = rff_segs
1337 .first()
1338 .and_then(|s| s.elements.first())
1339 .and_then(|e| e.get(1))
1340 .map(|s| s.as_str());
1341 let nad_mp_id = nad_segs
1342 .first()
1343 .and_then(|s| s.elements.get(1))
1344 .and_then(|e| e.first())
1345 .map(|s| s.as_str());
1346 match (rff_mp_id, nad_mp_id) {
1347 (Some(rff), Some(nad)) if !rff.is_empty() && !nad.is_empty() => {
1348 ConditionResult::from(rff == nad)
1349 }
1350 _ => ConditionResult::Unknown,
1351 }
1352 }
1353
1354 /// [51] Wenn BGM+Z54 vorhanden
1355 fn evaluate_51(&self, ctx: &EvaluationContext) -> ConditionResult {
1356 ctx.has_qualifier("BGM", 0, "Z54")
1357 }
1358
1359 /// [52] Wenn BGM+Z54 nicht vorhanden
1360 fn evaluate_52(&self, ctx: &EvaluationContext) -> ConditionResult {
1361 ctx.lacks_qualifier("BGM", 0, "Z54")
1362 }
1363
1364 /// [53] Diese SG40 darf genau einmal in der SG36 angegeben werden
1365 // REVIEW: Validates that SG40 appears exactly once within each SG36 instance. Uses the group navigator to count child SG40 instances per SG36 parent. PRICAT tx_group is SG17; SG36 is a nested group within SG17. Falls back to Unknown when no navigator is available. Medium confidence because the exact parent path ["SG17", "SG36"] is inferred from PRICAT structure conventions without an explicit segment reference. (medium confidence)
1366 fn evaluate_53(&self, ctx: &EvaluationContext) -> ConditionResult {
1367 // Diese SG40 darf genau einmal in der SG36 angegeben werden
1368 // For each SG36 instance, verify SG40 appears exactly once as a child group
1369 let nav = match ctx.navigator() {
1370 Some(n) => n,
1371 None => return ConditionResult::Unknown,
1372 };
1373 let sg36_count = nav.group_instance_count(&["SG17", "SG36"]);
1374 if sg36_count == 0 {
1375 return ConditionResult::Unknown;
1376 }
1377 for i in 0..sg36_count {
1378 let sg40_count = nav.child_group_instance_count(&["SG17", "SG36"], i, "SG40");
1379 if sg40_count != 1 {
1380 return ConditionResult::False;
1381 }
1382 }
1383 ConditionResult::True
1384 }
1385
1386 /// [54] Falls der Preis des Artikels gezont ist
1387 /// EXTERNAL: Requires context from outside the message.
1388 // REVIEW: 'Falls der Preis des Artikels gezont ist' describes whether the article has zone-based pricing — a product/business configuration attribute. While zone pricing might leave structural traces in the message (multiple zone segments), whether a price is fundamentally 'gezont' is a business model characteristic of the article that is external to the EDIFACT message content itself. (medium confidence)
1389 fn evaluate_54(&self, ctx: &EvaluationContext) -> ConditionResult {
1390 ctx.external.evaluate("article_price_is_zoned")
1391 }
1392
1393 /// [64] Wenn der Zeitpunkt im DTM+157 DE2380 ≥ 01.01.2026, 00:00 Uhr gesetzlicher deutscher Zeit
1394 fn evaluate_64(&self, ctx: &EvaluationContext) -> ConditionResult {
1395 let dtm_segs = ctx.find_segments_with_qualifier("DTM", 0, "157");
1396 match dtm_segs.first() {
1397 Some(dtm) => {
1398 let value = dtm
1399 .elements
1400 .first()
1401 .and_then(|e| e.get(1))
1402 .map(|s| s.as_str())
1403 .unwrap_or("");
1404 if value.len() >= 8 {
1405 ConditionResult::from(&value[..8] >= "20260101")
1406 } else {
1407 ConditionResult::Unknown
1408 }
1409 }
1410 None => ConditionResult::False, // segment absent → condition not applicable
1411 }
1412 }
1413
1414 /// [490] wenn Wert in diesem DE, an der Stelle CCYYMMDD ein Datum aus dem angegeben Zeitraum der Tabelle Kapitel 3.5 „Prozesszeitpunkt bei MESZ mit UTC“ ist
1415 fn evaluate_490(&self, ctx: &EvaluationContext) -> ConditionResult {
1416 match ctx.resolved_value {
1417 Some(val) => is_mesz_utc(val),
1418 None => ConditionResult::False,
1419 }
1420 }
1421
1422 /// [491] wenn Wert in diesem DE, an der Stelle CCYYMMDD ein Datum aus dem angegeben Zeitraum der Tabelle Kapitel 3.6 „Prozesszeitpunkt bei MEZ mit UTC“ ist
1423 fn evaluate_491(&self, ctx: &EvaluationContext) -> ConditionResult {
1424 match ctx.resolved_value {
1425 Some(val) => is_mez_utc(val),
1426 None => ConditionResult::False,
1427 }
1428 }
1429
1430 /// [492] wenn MP-ID in NAD+MR aus Sparte Strom
1431 /// EXTERNAL: Requires context from outside the message.
1432 // REVIEW: Checks if the NAD+MR market participant ID belongs to the electricity (Strom) sector. Sector membership cannot be determined from the EDIFACT message alone — requires external business context. (medium confidence)
1433 fn evaluate_492(&self, ctx: &EvaluationContext) -> ConditionResult {
1434 ctx.external.evaluate("recipient_is_strom")
1435 }
1436
1437 /// [494] Das hier genannte Datum muss der Zeitpunkt sein, zu dem das Dokument erstellt wurde, oder ein Zeitpunkt, der davor liegt
1438 fn evaluate_494(&self, _ctx: &EvaluationContext) -> ConditionResult {
1439 // Hinweis: Das hier genannte Datum muss der Zeitpunkt sein, zu dem das Dokument
1440 // erstellt wurde, oder ein Zeitpunkt, der davor liegt. Informational annotation
1441 // about the semantic meaning of the date field — always applies unconditionally.
1442 ConditionResult::True
1443 }
1444
1445 /// [495] Der Zeitpunkt muss ≤ dem Wert im DE2380 des DTM+137 sein
1446 // REVIEW: The condition checks that the Betrachtungszeitintervall (DTM+492) value is <= the Nachrichtendatum (DTM+137) value. Both DTM qualifiers appear in the segment reference for PRICAT. We extract DTM+137's DE2380 value as the threshold and use dtm_le to compare. Medium confidence because 'Der Zeitpunkt' could refer to DTM+157 (Gültigkeitsbeginn) instead of DTM+492 — the exact field being validated is not explicit in the description. (medium confidence)
1447 fn evaluate_495(&self, ctx: &EvaluationContext) -> ConditionResult {
1448 // Der Zeitpunkt (DTM+492 Betrachtungszeitintervall) muss <= DTM+137 (Nachrichtendatum) sein
1449 let dtm_137_segs = ctx.find_segments_with_qualifier("DTM", 0, "137");
1450 let dtm_137 = match dtm_137_segs.first() {
1451 Some(s) => s,
1452 None => return ConditionResult::Unknown,
1453 };
1454 let threshold = match dtm_137.elements.first().and_then(|e| e.get(1)) {
1455 Some(v) => v.clone(),
1456 None => return ConditionResult::Unknown,
1457 };
1458 ctx.dtm_le("492", &threshold)
1459 }
1460
1461 /// [502] Hinweis: Preis in Euro je MWh
1462 fn evaluate_502(&self, _ctx: &EvaluationContext) -> ConditionResult {
1463 ConditionResult::True
1464 }
1465
1466 /// [503] Hinweis: Hier ist immer der Wert 1000 einzutragen, da in DE5118 der Preis in €/MWh angegeben wird.
1467 fn evaluate_503(&self, _ctx: &EvaluationContext) -> ConditionResult {
1468 ConditionResult::True
1469 }
1470
1471 /// [504] Hinweis: Dokumentennummer der PRICAT
1472 fn evaluate_504(&self, _ctx: &EvaluationContext) -> ConditionResult {
1473 ConditionResult::True
1474 }
1475
1476 /// [512] Hinweis: Der genannte Wert gehört zum Intervall
1477 fn evaluate_512(&self, _ctx: &EvaluationContext) -> ConditionResult {
1478 ConditionResult::True
1479 }
1480
1481 /// [513] Hinweis: Die zum Preis gehörende Einheit ist in der Codeliste definiert
1482 fn evaluate_513(&self, _ctx: &EvaluationContext) -> ConditionResult {
1483 ConditionResult::True
1484 }
1485
1486 /// [519] Hinweis: Es darf nur eine Information im DE3148 übermittelt werden
1487 fn evaluate_519(&self, _ctx: &EvaluationContext) -> ConditionResult {
1488 ConditionResult::True
1489 }
1490
1491 /// [520] Hinweis: Falls der Preis des Artikels gezont ist, ist diese SG40 so oft zu wiederholen, bis alle Preise zu diesem Artikel genannt sind
1492 fn evaluate_520(&self, _ctx: &EvaluationContext) -> ConditionResult {
1493 ConditionResult::True
1494 }
1495
1496 /// [521] Hinweis: Je Artikel-ID muss in einem RNG der Wert dieses DE = 0 sein und in allen anderen RNG zu dieser Artikel-ID muss der Wert dieses DE mit dem Wert des DE6152 eines anderen RNG zu dieser Artike...
1497 fn evaluate_521(&self, _ctx: &EvaluationContext) -> ConditionResult {
1498 // Hinweis: informational annotation about RNG DE value relationships — one RNG must have value 0,
1499 // all others must equal DE6152 of another RNG for the same Artikel-ID
1500 ConditionResult::True
1501 }
1502
1503 /// [902] Format: Möglicher Wert: ≥ 0
1504 fn evaluate_902(&self, _ctx: &EvaluationContext) -> ConditionResult {
1505 ConditionResult::True
1506 }
1507
1508 /// [908] Format: Mögliche Werte: 1 bis n
1509 fn evaluate_908(&self, _ctx: &EvaluationContext) -> ConditionResult {
1510 ConditionResult::True
1511 }
1512
1513 /// [909] Format: Mögliche Werte: 0 bis n
1514 // REVIEW: Format condition specifying possible values 0 to n (non-negative). Applied to LIN DE1082 (Positionsnummer) as the most likely numeric element in PRICAT that can take values starting from 0. Medium confidence because the AHB context specifying which exact element this condition applies to is not included in the description. (medium confidence)
1515 fn evaluate_909(&self, ctx: &EvaluationContext) -> ConditionResult {
1516 // Format: Mögliche Werte 0 bis n — numeric value must be >= 0
1517 // Applied to LIN DE1082 (Positionsnummer) which can start from 0
1518 let lin_segs = ctx.find_segments("LIN");
1519 if lin_segs.is_empty() {
1520 return ConditionResult::Unknown;
1521 }
1522 for seg in &lin_segs {
1523 let val = match seg.elements.first().and_then(|e| e.first()) {
1524 Some(v) => v,
1525 None => return ConditionResult::Unknown,
1526 };
1527 match validate_numeric(val, ">=", 0.0) {
1528 ConditionResult::False => return ConditionResult::False,
1529 ConditionResult::Unknown => return ConditionResult::Unknown,
1530 ConditionResult::True => {}
1531 }
1532 }
1533 ConditionResult::True
1534 }
1535
1536 /// [911] Format: Mögliche Werte: 1 bis n, je Nachricht oder Segmentgruppe bei 1 beginnend und fortlaufend aufsteigend
1537 // REVIEW: Format condition specifying values 1 to n, starting at 1 and continuously ascending per message or segment group. This describes sequential position numbering, which in PRICAT is DE1082 in the LIN segment. The implementation collects all LIN segments and verifies their position numbers are 1, 2, 3, ... in order. Medium confidence because the specific element and scope (per-message vs per-SG17 group) are not explicit in the condition description alone. (medium confidence)
1538 fn evaluate_911(&self, ctx: &EvaluationContext) -> ConditionResult {
1539 // Format: Mögliche Werte 1 bis n, sequential per message/segment group starting at 1
1540 // Validates LIN DE1082 (Positionsnummer) is sequential starting from 1
1541 let lin_segs = ctx.find_segments("LIN");
1542 if lin_segs.is_empty() {
1543 return ConditionResult::Unknown;
1544 }
1545 let mut expected: u64 = 1;
1546 for seg in &lin_segs {
1547 let pos_str = match seg.elements.first().and_then(|e| e.first()) {
1548 Some(v) => v,
1549 None => return ConditionResult::Unknown,
1550 };
1551 let pos: u64 = match pos_str.parse() {
1552 Ok(n) => n,
1553 Err(_) => return ConditionResult::False,
1554 };
1555 if pos != expected {
1556 return ConditionResult::False;
1557 }
1558 expected += 1;
1559 }
1560 ConditionResult::True
1561 }
1562
1563 /// [912] Format: max. 6 Nachkommastellen
1564 // REVIEW: Max 6 decimal places format check. In PRICAT context, price values (PRI segment, element 0, component 1) are the primary numeric values with decimal places. Medium confidence because the exact segment this applies to depends on context — it could also apply to QTY or other numeric fields. (medium confidence)
1565 fn evaluate_912(&self, ctx: &EvaluationContext) -> ConditionResult {
1566 ctx.format_check("PRI", 0, 1, |val| validate_max_decimal_places(val, 6))
1567 }
1568
1569 /// [926] Format: Möglicher Wert: 0
1570 // REVIEW: Value must be exactly 0. Applies to a numeric data element — QTY is most common in PRICAT for this kind of constraint (e.g., minimum order quantity of 0). Medium confidence because the specific segment depends on where this condition is referenced in the AHB. (medium confidence)
1571 fn evaluate_926(&self, ctx: &EvaluationContext) -> ConditionResult {
1572 ctx.format_check("QTY", 0, 1, |val| validate_numeric(val, "==", 0.0))
1573 }
1574
1575 /// [929] Format: Möglicher Wert: 1000
1576 // REVIEW: Value must be exactly 1000. In PRICAT, 1000 is a common reference quantity (e.g., price per 1000 units in QTY). Medium confidence because the exact target segment depends on where this condition is used in the AHB. (medium confidence)
1577 fn evaluate_929(&self, ctx: &EvaluationContext) -> ConditionResult {
1578 ctx.format_check("QTY", 0, 1, |val| validate_numeric(val, "==", 1000.0))
1579 }
1580
1581 /// [931] Format: ZZZ = +00
1582 // REVIEW: DTM timezone check: EDIFACT DTM format 303 (CCYYMMDDHHMMzzz) or 719 encodes timezone offset. The condition requires ZZZ=+00 (UTC offset). elements[0][1] holds the datetime value string; checking it ends with '+00' covers standard EDIFACT timezone encoding. Medium confidence because the exact DTM qualifier and format code context is unknown without the segment structure reference. (medium confidence)
1583 fn evaluate_931(&self, ctx: &EvaluationContext) -> ConditionResult {
1584 // ZZZ = +00: timezone offset in DTM value must be +00
1585 // DTM format 303: YYYYMMDDHHMMzzz, timezone encoded as last part of elements[0][1]
1586 let dtm_segments = ctx.find_segments("DTM");
1587 for seg in &dtm_segments {
1588 if let Some(value) = seg.elements.first().and_then(|e| e.get(1)) {
1589 if !value.is_empty() {
1590 // Timezone +00 appears at end of value string
1591 if value.ends_with("+00") {
1592 return ConditionResult::True;
1593 } else {
1594 return ConditionResult::False;
1595 }
1596 }
1597 }
1598 }
1599 ConditionResult::Unknown
1600 }
1601
1602 /// [932] Format: HHMM = 2200
1603 // REVIEW: DTM time check: extracts HHMM portion from DTM value. Format 203 (CCYYMMDDHHmm) places hours at positions 8-11. Format 401 (HHmm) starts at position 0. Condition requires exactly 2200. Medium confidence because the specific DTM qualifier context in PRICAT is unknown without the segment structure reference. (medium confidence)
1604 fn evaluate_932(&self, ctx: &EvaluationContext) -> ConditionResult {
1605 // HHMM = 2200: time value in DTM must be 2200
1606 // In DTM format 203 (YYYYMMDDHHMM) or 401 (HHMM), the time portion is HHMM
1607 let dtm_segments = ctx.find_segments("DTM");
1608 for seg in &dtm_segments {
1609 if let Some(value) = seg.elements.first().and_then(|e| e.get(1)) {
1610 let format_code = seg
1611 .elements
1612 .first()
1613 .and_then(|e| e.get(2))
1614 .map(|s| s.as_str())
1615 .unwrap_or("");
1616 let time_part = match format_code {
1617 "203" if value.len() >= 12 => &value[8..12],
1618 "401" if value.len() >= 4 => &value[0..4],
1619 _ if value.len() >= 12 => &value[8..12],
1620 _ => continue,
1621 };
1622 if time_part == "2200" {
1623 return ConditionResult::True;
1624 } else {
1625 return ConditionResult::False;
1626 }
1627 }
1628 }
1629 ConditionResult::Unknown
1630 }
1631
1632 /// [933] Format: HHMM = 2300
1633 // REVIEW: Same structure as condition 932 but checks for 2300 instead of 2200. Extracts HHMM portion from DTM value using format code to determine position. (medium confidence)
1634 fn evaluate_933(&self, ctx: &EvaluationContext) -> ConditionResult {
1635 // HHMM = 2300: time value in DTM must be 2300
1636 let dtm_segments = ctx.find_segments("DTM");
1637 for seg in &dtm_segments {
1638 if let Some(value) = seg.elements.first().and_then(|e| e.get(1)) {
1639 let format_code = seg
1640 .elements
1641 .first()
1642 .and_then(|e| e.get(2))
1643 .map(|s| s.as_str())
1644 .unwrap_or("");
1645 let time_part = match format_code {
1646 "203" if value.len() >= 12 => &value[8..12],
1647 "401" if value.len() >= 4 => &value[0..4],
1648 _ if value.len() >= 12 => &value[8..12],
1649 _ => continue,
1650 };
1651 if time_part == "2300" {
1652 return ConditionResult::True;
1653 } else {
1654 return ConditionResult::False;
1655 }
1656 }
1657 }
1658 ConditionResult::Unknown
1659 }
1660
1661 /// [937] Format: keine Nachkommastelle
1662 // REVIEW: No decimal places allowed — integer values only. Implemented as validate_max_decimal_places with 0. In PRICAT, this typically applies to QTY (quantity must be whole number). Medium confidence because the exact target segment depends on AHB context. (medium confidence)
1663 fn evaluate_937(&self, ctx: &EvaluationContext) -> ConditionResult {
1664 ctx.format_check("QTY", 0, 1, |val| validate_max_decimal_places(val, 0))
1665 }
1666
1667 /// [939] Format: Die Zeichenkette muss die Zeichen @ und . enthalten
1668 // REVIEW: Email address format validation: the string must contain both '@' and '.'. This pattern matches COM segment (communication address) with channel code EM (Electronic Mail). elements[0][0] holds the address, elements[0][1] holds the channel qualifier. Checks channel=EM first, then falls back to any non-empty COM value. Medium confidence because PRICAT segment structure reference not provided. (medium confidence)
1669 fn evaluate_939(&self, ctx: &EvaluationContext) -> ConditionResult {
1670 // Email format: string must contain both '@' and '.'
1671 // Typically applies to COM segment (communication channel EM = email)
1672 let com_segments = ctx.find_segments("COM");
1673 for seg in &com_segments {
1674 // COM: elements[0][0] = communication address, elements[0][1] = channel code
1675 let channel = seg
1676 .elements
1677 .first()
1678 .and_then(|e| e.get(1))
1679 .map(|s| s.as_str())
1680 .unwrap_or("");
1681 if channel == "EM" {
1682 if let Some(address) = seg.elements.first().and_then(|e| e.first()) {
1683 let contains_at = address.contains('@');
1684 let contains_dot = address.contains('.');
1685 return ConditionResult::from(contains_at && contains_dot);
1686 }
1687 }
1688 }
1689 // Fallback: check any COM value for @ and .
1690 for seg in &com_segments {
1691 if let Some(address) = seg.elements.first().and_then(|e| e.first()) {
1692 if !address.is_empty() {
1693 return ConditionResult::from(address.contains('@') && address.contains('.'));
1694 }
1695 }
1696 }
1697 ConditionResult::Unknown
1698 }
1699
1700 /// [940] Format: Die Zeichenkette muss mit dem Zeichen + beginnen und danach dürfen nur noch Ziffern folgen
1701 // REVIEW: Phone number format: must start with '+' then only digits (international E.164 format). Applies to COM segment with telephone/fax channel codes (TE, FX, AJ). elements[0][0] = number, elements[0][1] = channel code. Medium confidence because PRICAT segment structure reference not provided. (medium confidence)
1702 fn evaluate_940(&self, ctx: &EvaluationContext) -> ConditionResult {
1703 // Phone number format: must start with '+' followed only by digits
1704 // Typically applies to COM segment (TEL/FAX channel)
1705 let com_segments = ctx.find_segments("COM");
1706 for seg in &com_segments {
1707 let channel = seg
1708 .elements
1709 .first()
1710 .and_then(|e| e.get(1))
1711 .map(|s| s.as_str())
1712 .unwrap_or("");
1713 if matches!(channel, "TE" | "FX" | "AJ") {
1714 if let Some(number) = seg.elements.first().and_then(|e| e.first()) {
1715 if !number.is_empty() {
1716 let valid = number.starts_with('+')
1717 && number.len() > 1
1718 && number[1..].chars().all(|c| c.is_ascii_digit());
1719 return ConditionResult::from(valid);
1720 }
1721 }
1722 }
1723 }
1724 // Fallback: check any COM value for +digit format
1725 for seg in &com_segments {
1726 if let Some(number) = seg.elements.first().and_then(|e| e.first()) {
1727 if !number.is_empty() {
1728 let valid = number.starts_with('+')
1729 && number.len() > 1
1730 && number[1..].chars().all(|c| c.is_ascii_digit());
1731 return ConditionResult::from(valid);
1732 }
1733 }
1734 }
1735 ConditionResult::Unknown
1736 }
1737
1738 /// [941] Format: Artikelnummer
1739 // REVIEW: Article number format validation on PIA segment (Additional Product ID), element 1, component 0. The pattern n1-n2-n1-n3 is a common PRICAT Artikelnummer format in the German energy market. Medium confidence because the exact digit-segment pattern may differ — should be verified against the specific AHB table for this condition reference. (medium confidence)
1740 fn evaluate_941(&self, ctx: &EvaluationContext) -> ConditionResult {
1741 ctx.format_check("PIA", 1, 0, |val| {
1742 validate_artikel_pattern(val, &[1, 2, 1, 3])
1743 })
1744 }
1745
1746 /// [942] Format: n1-n2-n1-n3
1747 fn evaluate_942(&self, ctx: &EvaluationContext) -> ConditionResult {
1748 ctx.format_check("PIA", 1, 0, |val| {
1749 validate_artikel_pattern(val, &[1, 2, 1, 3])
1750 })
1751 }
1752
1753 /// [946] Format: max. 11 Nachkommastellen
1754 // REVIEW: Format: max. 11 Nachkommastellen — validates that a numeric value has at most 11 decimal places. In PRICAT, price values appear in PRI segment element 0 component 1. Using PRI as the most likely price segment in PRICAT context. (medium confidence)
1755 fn evaluate_946(&self, ctx: &EvaluationContext) -> ConditionResult {
1756 ctx.format_check("PRI", 0, 1, |val| validate_max_decimal_places(val, 11))
1757 }
1758
1759 /// [948] Format: n1-n2-n1-n8-n2
1760 fn evaluate_948(&self, ctx: &EvaluationContext) -> ConditionResult {
1761 ctx.format_check("PIA", 1, 0, |val| {
1762 validate_artikel_pattern(val, &[1, 2, 1, 8, 2])
1763 })
1764 }
1765
1766 /// [949] Format: n1-n2-n1-n8-n2-n1
1767 fn evaluate_949(&self, ctx: &EvaluationContext) -> ConditionResult {
1768 ctx.format_check("PIA", 1, 0, |val| {
1769 validate_artikel_pattern(val, &[1, 2, 1, 8, 2, 1])
1770 })
1771 }
1772
1773 /// [957] Format: n1-n2-n1-n8
1774 fn evaluate_957(&self, ctx: &EvaluationContext) -> ConditionResult {
1775 ctx.format_check("PIA", 1, 0, |val| {
1776 validate_artikel_pattern(val, &[1, 2, 1, 8])
1777 })
1778 }
1779
1780 /// [959] Format: n13-n2
1781 // REVIEW: Format: n13-n2 is an Artikelnummer pattern — 13 digits, dash, 2 digits. In PRICAT, article identifiers appear in PIA element 1 component 0. Using validate_artikel_pattern with &[13, 2]. Medium confidence because the exact target segment/element depends on AHB context not provided here. (medium confidence)
1782 fn evaluate_959(&self, ctx: &EvaluationContext) -> ConditionResult {
1783 ctx.format_check("PIA", 1, 0, |val| validate_artikel_pattern(val, &[13, 2]))
1784 }
1785
1786 /// [968] Format: Möglicher Wert: ≤ 0
1787 // REVIEW: Format: Möglicher Wert: ≤ 0 means the numeric value must be less than or equal to zero. In PRICAT, PRI segment element 0 component 1 holds the price amount. Using validate_numeric with "<=", 0.0. Medium confidence because the exact target segment depends on AHB context — could also be MOA or another numeric field. (medium confidence)
1788 fn evaluate_968(&self, ctx: &EvaluationContext) -> ConditionResult {
1789 ctx.format_check("PRI", 0, 1, |val| validate_numeric(val, "<=", 0.0))
1790 }
1791}
1792
1793// HAND-EDITED: helpers for PRICAT conditions comparing Artikel-IDs (LIN C212
1794// DE7140, "<Gruppenartikel-ID>-<nn>") and price zones (SG40 RNG C280).
1795
1796/// The Artikel-ID of the SG36 at `path`, split at its last "-".
1797fn article_at(ctx: &EvaluationContext, path: &[(&str, usize)]) -> Option<(String, u32)> {
1798 let lin = ctx.find_segments_at(path, "LIN");
1799 let code = lin.first()?.get_component(2, 0).to_string();
1800 let (prefix, number) = code.rsplit_once('-')?;
1801 Some((prefix.to_string(), number.parse().ok()?))
1802}
1803
1804/// Every SG36 of the message, as scope paths.
1805fn all_articles<'a>(ctx: &EvaluationContext<'a>) -> Vec<Vec<(&'a str, usize)>> {
1806 let Some(nav) = ctx.navigator else {
1807 return Vec::new();
1808 };
1809 let mut out = Vec::new();
1810 for g in 0..nav.child_instance_count(&[], "SG17") {
1811 for a in 0..nav.child_instance_count(&[("SG17", g)], "SG36") {
1812 out.push(vec![("SG17", g), ("SG36", a)]);
1813 }
1814 }
1815 out
1816}
1817
1818/// The SG40 (price zones) of the SG36 at `path`.
1819fn zone_paths<'a>(
1820 ctx: &EvaluationContext<'a>,
1821 path: &[(&'a str, usize)],
1822) -> Vec<Vec<(&'a str, usize)>> {
1823 let Some(nav) = ctx.navigator else {
1824 return Vec::new();
1825 };
1826 (0..nav.child_instance_count(path, "SG40"))
1827 .map(|i| {
1828 let mut zone = path.to_vec();
1829 zone.push(("SG40", i));
1830 zone
1831 })
1832 .collect()
1833}
1834
1835/// The lower (DE6162) and upper (DE6152) bound of each RNG at `path`.
1836fn zones_at(ctx: &EvaluationContext, path: &[(&str, usize)]) -> Vec<(Option<f64>, Option<f64>)> {
1837 ctx.find_segments_at(path, "RNG")
1838 .iter()
1839 .map(|s| {
1840 (
1841 s.get_component(1, 1).replace(',', ".").parse().ok(),
1842 s.get_component(1, 2).replace(',', ".").parse().ok(),
1843 )
1844 })
1845 .collect()
1846}