automapper-validation 0.14.1

AHB condition expression parsing, evaluation, and EDIFACT validation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
// <auto-generated>
// Generated by automapper-generator generate-conditions
// AHB: xml-migs-and-ahbs/FV2504/PRICAT_AHB_2_0e_Fehlerkorrektur_20250623.xml
// Generated: 2026-03-12T10:05:58Z
// </auto-generated>

// LLM-produced bodies aren't idiomatic Rust — silence stylistic lints at
// file scope so `cargo clippy -D warnings` stays green. Correctness,
// suspicious, and perf categories stay on so real bugs still surface.
#![allow(clippy::style, clippy::complexity)]

#[allow(unused_imports)]
use crate::eval::format_validators::*;
use crate::eval::{ConditionEvaluator, ConditionResult, EvaluationContext};

/// Generated condition evaluator for PRICAT FV2504.
pub struct PricatConditionEvaluatorFV2504 {
    // External condition IDs that require runtime context.
    external_conditions: std::collections::HashSet<u32>,
}

impl Default for PricatConditionEvaluatorFV2504 {
    fn default() -> Self {
        let mut external_conditions = std::collections::HashSet::new();
        external_conditions.insert(1);
        external_conditions.insert(14);
        external_conditions.insert(19);
        external_conditions.insert(22);
        external_conditions.insert(30);
        external_conditions.insert(36);
        external_conditions.insert(39);
        external_conditions.insert(40);
        external_conditions.insert(41);
        external_conditions.insert(42);
        external_conditions.insert(45);
        external_conditions.insert(46);
        external_conditions.insert(54);
        external_conditions.insert(492);
        Self {
            external_conditions,
        }
    }
}

impl ConditionEvaluator for PricatConditionEvaluatorFV2504 {
    fn message_type(&self) -> &str {
        "PRICAT"
    }

    fn format_version(&self) -> &str {
        "FV2504"
    }

    fn evaluate(&self, condition: u32, ctx: &EvaluationContext) -> ConditionResult {
        match condition {
            1 => self.evaluate_1(ctx),
            2 => self.evaluate_2(ctx),
            3 => self.evaluate_3(ctx),
            4 => self.evaluate_4(ctx),
            5 => self.evaluate_5(ctx),
            6 => self.evaluate_6(ctx),
            7 => self.evaluate_7(ctx),
            9 => self.evaluate_9(ctx),
            10 => self.evaluate_10(ctx),
            12 => self.evaluate_12(ctx),
            14 => self.evaluate_14(ctx),
            19 => self.evaluate_19(ctx),
            22 => self.evaluate_22(ctx),
            24 => self.evaluate_24(ctx),
            26 => self.evaluate_26(ctx),
            27 => self.evaluate_27(ctx),
            28 => self.evaluate_28(ctx),
            29 => self.evaluate_29(ctx),
            30 => self.evaluate_30(ctx),
            31 => self.evaluate_31(ctx),
            32 => self.evaluate_32(ctx),
            33 => self.evaluate_33(ctx),
            34 => self.evaluate_34(ctx),
            36 => self.evaluate_36(ctx),
            37 => self.evaluate_37(ctx),
            38 => self.evaluate_38(ctx),
            39 => self.evaluate_39(ctx),
            40 => self.evaluate_40(ctx),
            41 => self.evaluate_41(ctx),
            42 => self.evaluate_42(ctx),
            43 => self.evaluate_43(ctx),
            44 => self.evaluate_44(ctx),
            45 => self.evaluate_45(ctx),
            46 => self.evaluate_46(ctx),
            47 => self.evaluate_47(ctx),
            48 => self.evaluate_48(ctx),
            49 => self.evaluate_49(ctx),
            50 => self.evaluate_50(ctx),
            51 => self.evaluate_51(ctx),
            52 => self.evaluate_52(ctx),
            53 => self.evaluate_53(ctx),
            54 => self.evaluate_54(ctx),
            55 => self.evaluate_55(ctx),
            64 => self.evaluate_64(ctx),
            490 => self.evaluate_490(ctx),
            491 => self.evaluate_491(ctx),
            492 => self.evaluate_492(ctx),
            494 => self.evaluate_494(ctx),
            495 => self.evaluate_495(ctx),
            502 => self.evaluate_502(ctx),
            503 => self.evaluate_503(ctx),
            504 => self.evaluate_504(ctx),
            511 => self.evaluate_511(ctx),
            512 => self.evaluate_512(ctx),
            513 => self.evaluate_513(ctx),
            519 => self.evaluate_519(ctx),
            520 => self.evaluate_520(ctx),
            521 => self.evaluate_521(ctx),
            902 => self.evaluate_902(ctx),
            908 => self.evaluate_908(ctx),
            909 => self.evaluate_909(ctx),
            911 => self.evaluate_911(ctx),
            912 => self.evaluate_912(ctx),
            926 => self.evaluate_926(ctx),
            929 => self.evaluate_929(ctx),
            931 => self.evaluate_931(ctx),
            932 => self.evaluate_932(ctx),
            933 => self.evaluate_933(ctx),
            937 => self.evaluate_937(ctx),
            939 => self.evaluate_939(ctx),
            940 => self.evaluate_940(ctx),
            941 => self.evaluate_941(ctx),
            942 => self.evaluate_942(ctx),
            946 => self.evaluate_946(ctx),
            948 => self.evaluate_948(ctx),
            949 => self.evaluate_949(ctx),
            957 => self.evaluate_957(ctx),
            959 => self.evaluate_959(ctx),
            968 => self.evaluate_968(ctx),
            _ => ConditionResult::Unknown,
        }
    }

    fn is_external(&self, condition: u32) -> bool {
        self.external_conditions.contains(&condition)
    }
    fn is_known(&self, condition: u32) -> bool {
        matches!(
            condition,
            1 | 2
                | 3
                | 4
                | 5
                | 6
                | 7
                | 9
                | 10
                | 12
                | 14
                | 19
                | 22
                | 24
                | 26
                | 27
                | 28
                | 29
                | 30
                | 31
                | 32
                | 33
                | 34
                | 36
                | 37
                | 38
                | 39
                | 40
                | 41
                | 42
                | 43
                | 44
                | 45
                | 46
                | 47
                | 48
                | 49
                | 50
                | 51
                | 52
                | 53
                | 54
                | 55
                | 64
                | 490
                | 491
                | 492
                | 494
                | 495
                | 502
                | 503
                | 504
                | 511
                | 512
                | 513
                | 519
                | 520
                | 521
                | 902
                | 908
                | 909
                | 911
                | 912
                | 926
                | 929
                | 931
                | 932
                | 933
                | 937
                | 939
                | 940
                | 941
                | 942
                | 946
                | 948
                | 949
                | 957
                | 959
                | 968
        )
    }
}

impl PricatConditionEvaluatorFV2504 {
    /// [10] Wenn eine weitere Zone für diese Gruppenartikel-ID vorhanden
    fn evaluate_10(&self, ctx: &EvaluationContext) -> ConditionResult {
        // In PRICAT each SG36 is a "Zone" (price range), identified by its
        // LIN DE7140 (Artikel-ID). The Gruppenartikel-ID is the prefix before
        // the last '-' (e.g. LIN "1-01-6-005" → group "1-01-6"). The
        // condition is True when two or more SG36s share the same
        // Gruppenartikel-ID prefix — i.e. multiple zones exist within the
        // same article group.
        let nav = match ctx.navigator() {
            Some(n) => n,
            None => return ConditionResult::Unknown,
        };
        let sg36_count = nav.group_instance_count(&["SG17", "SG36"]);
        if sg36_count < 2 {
            return ConditionResult::False;
        }
        let mut prefixes: Vec<String> = Vec::with_capacity(sg36_count);
        for i in 0..sg36_count {
            let lin_segs = nav.find_segments_in_group("LIN", &["SG17", "SG36"], i);
            if let Some(v) = lin_segs
                .first()
                .and_then(|s| s.elements.get(2))
                .and_then(|e| e.first())
            {
                if let Some(pos) = v.rfind('-') {
                    prefixes.push(v[..pos].to_string());
                }
            }
        }
        for i in 0..prefixes.len() {
            for j in (i + 1)..prefixes.len() {
                if !prefixes[i].is_empty() && prefixes[i] == prefixes[j] {
                    return ConditionResult::True;
                }
            }
        }
        ConditionResult::False
    }

    /// [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" genannt sind
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_45(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external
            .evaluate("pricat_artikel_abrechnung_messstellenbetrieb_strom")
    }

    /// [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 den Universalbestellprozess für die Sparte Strom" genannt sind
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_46(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external
            .evaluate("pricat_artikel_universalbestellprozess_strom")
    }

    /// [54] Falls der Preis des Artikels gezont ist
    /// EXTERNAL: Requires context from outside the message.
    // 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)
    fn evaluate_54(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("article_price_is_zoned")
    }

    /// [55] Wenn eine weitere Zone für diese Artikel-ID vorhanden
    fn evaluate_55(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Artikel-ID is the full LIN DE7140 (no prefix stripping). True when
        // two or more SG36 "zones" carry the same full Artikel-ID — i.e. a
        // duplicate/overlapping zone definition exists for one article.
        let nav = match ctx.navigator() {
            Some(n) => n,
            None => return ConditionResult::Unknown,
        };
        let sg36_count = nav.group_instance_count(&["SG17", "SG36"]);
        if sg36_count < 2 {
            return ConditionResult::False;
        }
        let mut ids: Vec<String> = Vec::with_capacity(sg36_count);
        for i in 0..sg36_count {
            let lin_segs = nav.find_segments_in_group("LIN", &["SG17", "SG36"], i);
            if let Some(v) = lin_segs
                .first()
                .and_then(|s| s.elements.get(2))
                .and_then(|e| e.first())
            {
                ids.push(v.clone());
            }
        }
        for i in 0..ids.len() {
            for j in (i + 1)..ids.len() {
                if !ids[i].is_empty() && ids[i] == ids[j] {
                    return ConditionResult::True;
                }
            }
        }
        ConditionResult::False
    }

    /// [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
    fn evaluate_490(&self, ctx: &EvaluationContext) -> ConditionResult {
        match ctx.resolved_value {
            Some(val) => is_mesz_utc(val),
            None => ConditionResult::False,
        }
    }

    /// [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
    fn evaluate_491(&self, ctx: &EvaluationContext) -> ConditionResult {
        match ctx.resolved_value {
            Some(val) => is_mez_utc(val),
            None => ConditionResult::False,
        }
    }

    /// [1] Wenn Vorgängerversion vorhanden
    /// EXTERNAL: Requires context from outside the message.
    // 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)
    fn evaluate_1(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("previous_version_exists")
    }

    /// [2] Wenn in dieser SG36 LIN in DE7140 9990001000813 vorhanden
    fn evaluate_2(&self, ctx: &EvaluationContext) -> ConditionResult {
        let values = ctx.collect_group_values("LIN", 2, 0, &["SG36"]);
        ConditionResult::from(values.iter().any(|(_, v)| v == "9990001000813"))
    }

    /// [3] Wenn IMD+X vorhanden
    fn evaluate_3(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("IMD", 0, "X")
    }

    /// [4] Wenn SG36 IMD+C in diesem IMD vorhanden
    fn evaluate_4(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("IMD", 0, "C", &["SG36"])
    }

    /// [5] Wenn SG36 IMD+X in diesem IMD vorhanden
    fn evaluate_5(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("IMD", 0, "X", &["SG36"])
    }

    /// [6] Wenn in dieser SG36 LIN in DE7140 9990001000798 vorhanden
    fn evaluate_6(&self, ctx: &EvaluationContext) -> ConditionResult {
        let values = ctx.collect_group_values("LIN", 2, 0, &["SG36"]);
        ConditionResult::from(values.iter().any(|(_, v)| v == "9990001000798"))
    }

    /// [7] Wenn in dieser SG36 LIN in DE7140 9990001000798 nicht vorhanden
    fn evaluate_7(&self, ctx: &EvaluationContext) -> ConditionResult {
        let values = ctx.collect_group_values("LIN", 2, 0, &["SG36"]);
        ConditionResult::from(!values.iter().any(|(_, v)| v == "9990001000798"))
    }

    /// [9] Wenn BGM DE1373 =11 nicht vorhanden
    fn evaluate_9(&self, ctx: &EvaluationContext) -> ConditionResult {
        match ctx.find_segment("BGM") {
            None => ConditionResult::False, // segment absent → condition not applicable
            Some(seg) => {
                let val = seg
                    .elements
                    .get(4)
                    .and_then(|e| e.first())
                    .map(|s| s.as_str())
                    .unwrap_or("");
                ConditionResult::from(val != "11")
            }
        }
    }

    /// [12] je UNB ist nur eine Nachricht mit BGM+Z04 in der Übertragungsdatei erlaubt (nur eine Nachricht je Übertragungsdatei)
    // 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)
    fn evaluate_12(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("BGM", 0, "Z04")
    }

    /// [14] je UNB ist maximal je Code aus DE1001 eine Nachricht in der Übertragungsdatei erlaubt
    /// EXTERNAL: Requires context from outside the message.
    // 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)
    fn evaluate_14(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("max_one_message_per_type_in_unb")
    }

    /// [19] Nur MP-ID aus Sparte Strom
    /// EXTERNAL: Requires context from outside the message.
    // 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)
    fn evaluate_19(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("mp_id_is_strom_sector")
    }

    /// [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
    /// EXTERNAL: Requires context from outside the message.
    // 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)
    fn evaluate_22(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("article_id_has_pricat_price_flag")
    }

    /// [24] Wenn in dieser SG36 Wert von LIN DE7140 im Format n1-n2-n1-n8-n2-n1
    fn evaluate_24(&self, ctx: &EvaluationContext) -> ConditionResult {
        let values = ctx.collect_group_values("LIN", 2, 0, &["SG36"]);
        ConditionResult::from(values.iter().any(|(_, val)| {
            let parts: Vec<&str> = val.split('-').collect();
            if parts.len() != 6 {
                return false;
            }
            let expected_lens = [1usize, 2, 1, 8, 2, 1];
            parts
                .iter()
                .zip(expected_lens.iter())
                .all(|(p, &len)| p.len() == len && p.chars().all(|ch| ch.is_ascii_digit()))
        }))
    }

    /// [26] Wenn BGM DE1001 = Z70 vorhanden
    fn evaluate_26(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("BGM", 0, "Z70")
    }

    /// [27] Wenn BGM DE1001 = Z70 nicht vorhanden
    fn evaluate_27(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.lacks_qualifier("BGM", 0, "Z70")
    }

    /// [28] Wenn die zugehörige Artikel-ID in der letzten Stelle eine 1 ist
    // 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)
    fn evaluate_28(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Wenn die zugehörige Artikel-ID in der letzten Stelle eine 1 ist
        // Artikel-ID is in PIA segment, elements[1][0]
        let segs = ctx.find_segments("PIA");
        match segs
            .first()
            .and_then(|s| s.elements.get(1))
            .and_then(|e| e.first())
        {
            Some(val) => match val.chars().last() {
                Some('1') => ConditionResult::True,
                Some(c) if c.is_ascii_digit() => ConditionResult::False,
                Some(_) => ConditionResult::False,
                None => ConditionResult::False, // segment absent → condition not applicable
            },
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [29] Wenn die zugehörige Artikel-ID in der letzten Stelle &gt; 1 ist
    // 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)
    fn evaluate_29(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Wenn die zugehörige Artikel-ID in der letzten Stelle > 1 ist
        // Artikel-ID is in PIA segment, elements[1][0]
        let segs = ctx.find_segments("PIA");
        match segs
            .first()
            .and_then(|s| s.elements.get(1))
            .and_then(|e| e.first())
        {
            Some(val) => match val.chars().last() {
                Some(c) if c.is_ascii_digit() && c > '1' => ConditionResult::True,
                Some(c) if c.is_ascii_digit() => ConditionResult::False,
                Some(_) => ConditionResult::False,
                None => ConditionResult::False, // segment absent → condition not applicable
            },
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [30] wenn MP-ID in SG2 NAD+MR in der Rolle LF
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_30(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("recipient_is_lf")
    }

    /// [31] wenn BGM DE1001 = Z32
    fn evaluate_31(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("BGM", 0, "Z32")
    }

    /// [32] wenn der Zeitpunkt im DTM+157 DE2380 &lt; 01.01.2024 00:00 Uhr gesetzlicher deutscher Zeit
    // 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)
    fn evaluate_32(&self, ctx: &EvaluationContext) -> ConditionResult {
        {
            let dtms = ctx.find_segments_with_qualifier("DTM", 0, "157");
            match dtms.first() {
                Some(dtm) => {
                    match dtm
                        .elements
                        .first()
                        .and_then(|e| e.get(1))
                        .map(|s| s.as_str())
                    {
                        Some(value) if !value.is_empty() => {
                            // Format 303: YYYYMMDDHHMM — string comparison valid for numeric date strings
                            // 01.01.2024 00:00 German legal time → "202401010000"
                            ConditionResult::from(value < "202401010000")
                        }
                        _ => ConditionResult::Unknown,
                    }
                }
                None => ConditionResult::False, // segment absent → condition not applicable
            }
        }
    }

    /// [33] wenn der Zeitpunkt im DTM+157 DE2380 ≥ 01.01.2024 00:00 Uhr gesetzlicher deutscher Zeit
    // REVIEW: Mirror of condition 32 with >= comparison. DTM+157 DE2380 at elements[0][1], format 303. Returns Unknown if segment absent. (medium confidence)
    fn evaluate_33(&self, ctx: &EvaluationContext) -> ConditionResult {
        {
            let dtms = ctx.find_segments_with_qualifier("DTM", 0, "157");
            match dtms.first() {
                Some(dtm) => {
                    match dtm
                        .elements
                        .first()
                        .and_then(|e| e.get(1))
                        .map(|s| s.as_str())
                    {
                        Some(value) if !value.is_empty() => {
                            // Format 303: YYYYMMDDHHMM — string comparison valid for numeric date strings
                            // 01.01.2024 00:00 German legal time → "202401010000"
                            ConditionResult::from(value >= "202401010000")
                        }
                        _ => ConditionResult::Unknown,
                    }
                }
                None => ConditionResult::False, // segment absent → condition not applicable
            }
        }
    }

    /// [34] wenn BGM DE1001 = Z77
    fn evaluate_34(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("BGM", 0, "Z77")
    }

    /// [36] Wenn MP-ID in SG2 NAD+MR in der Rolle NB
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_36(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("recipient_is_nb")
    }

    /// [37] Wenn im DE3155 in demselben COM der Code EM vorhanden ist
    // 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)
    fn evaluate_37(&self, ctx: &EvaluationContext) -> ConditionResult {
        {
            let coms = ctx.find_segments("COM");
            ConditionResult::from(coms.iter().any(|s| {
                s.elements
                    .first()
                    .and_then(|e| e.get(1))
                    .is_some_and(|v| v == "EM")
            }))
        }
    }

    /// [38] Wenn im DE3155 in demselben COM der Code TE / FX / AJ / AL vorhanden ist
    // REVIEW: Same COM segment structure as condition 37. Checks DE3155 for any of TE (telephone), FX (fax), AJ, AL channel codes. (medium confidence)
    fn evaluate_38(&self, ctx: &EvaluationContext) -> ConditionResult {
        {
            let coms = ctx.find_segments("COM");
            ConditionResult::from(coms.iter().any(|s| {
                s.elements
                    .first()
                    .and_then(|e| e.get(1))
                    .is_some_and(|v| matches!(v.as_str(), "TE" | "FX" | "AJ" | "AL"))
            }))
        }
    }

    /// [39] Es sind nur Werte aus der EDI@Energy Codeliste der Artikelnummern und Artikel-ID erlaubt, die in der Spalte MaBiS ein X haben
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_39(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("article_id_in_mabis_codelist")
    }

    /// [40] Es sind nur Werte aus der EDI@Energy Codeliste der Artikelnummern und Artikel-ID erlaubt, die in der Spalte H ein X haben
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_40(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("article_id_in_h_codelist")
    }

    /// [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
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_41(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("article_id_in_pricat_codelist")
    }

    /// [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
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_42(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external
            .evaluate("article_id_valid_pricat_formation_rule")
    }

    /// [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
    // 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)
    fn evaluate_43(&self, ctx: &EvaluationContext) -> ConditionResult {
        let bgm = match ctx.find_segment("BGM") {
            Some(s) => s,
            None => return ConditionResult::Unknown,
        };
        if bgm
            .elements
            .first()
            .and_then(|e| e.first())
            .map(|s| s.as_str())
            != Some("Z32")
        {
            return ConditionResult::False;
        }
        let lin_segments = ctx.find_segments("LIN");
        let has_hyphen_format = lin_segments.iter().any(|s| {
            s.elements
                .get(2)
                .and_then(|e| e.first())
                .map_or(false, |v| v.contains('-'))
        });
        if !has_hyphen_format {
            return ConditionResult::False;
        }
        let dtm_segs = ctx.find_segments_with_qualifier("DTM", 0, "157");
        match dtm_segs.first() {
            Some(dtm) => {
                let value = dtm
                    .elements
                    .first()
                    .and_then(|e| e.get(1))
                    .map(|s| s.as_str())
                    .unwrap_or("");
                if value.len() >= 8 {
                    ConditionResult::from(&value[..8] >= "20240101")
                } else {
                    ConditionResult::Unknown
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [44] Wenn BGM DE1001 = Z77, dann muss der hier genannte Zeitpunkt ≥ 01.10.2023 00:00 Uhr gesetzlicher deutscher Zeit sein.
    // REVIEW: Checks BGM DE1001==Z77 then verifies DTM+157 value >= 20231001 (01.10.2023). Medium confidence because the referenced time point is assumed to be DTM+157 (Gültigkeitsbeginn). (medium confidence)
    fn evaluate_44(&self, ctx: &EvaluationContext) -> ConditionResult {
        let bgm = match ctx.find_segment("BGM") {
            Some(s) => s,
            None => return ConditionResult::Unknown,
        };
        if bgm
            .elements
            .first()
            .and_then(|e| e.first())
            .map(|s| s.as_str())
            != Some("Z77")
        {
            return ConditionResult::False;
        }
        let dtm_segs = ctx.find_segments_with_qualifier("DTM", 0, "157");
        match dtm_segs.first() {
            Some(dtm) => {
                let value = dtm
                    .elements
                    .first()
                    .and_then(|e| e.get(1))
                    .map(|s| s.as_str())
                    .unwrap_or("");
                if value.len() >= 8 {
                    ConditionResult::from(&value[..8] >= "20231001")
                } else {
                    ConditionResult::Unknown
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [47] Wenn BGM DE1001 = Z32 und LIN DE7140 im Format n13, dann muss der hier genannte Zeitpunkt &lt; 01.01.2024 00:00 Uhr gesetzlicher deutscher Zeit sein
    // 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)
    fn evaluate_47(&self, ctx: &EvaluationContext) -> ConditionResult {
        let bgm = match ctx.find_segment("BGM") {
            Some(s) => s,
            None => return ConditionResult::Unknown,
        };
        if bgm
            .elements
            .first()
            .and_then(|e| e.first())
            .map(|s| s.as_str())
            != Some("Z32")
        {
            return ConditionResult::False;
        }
        let lin_segments = ctx.find_segments("LIN");
        let has_n13_format = lin_segments.iter().any(|s| {
            s.elements
                .get(2)
                .and_then(|e| e.first())
                .map_or(false, |v| {
                    !v.contains('-') && v.len() == 13 && v.chars().all(|c| c.is_ascii_digit())
                })
        });
        if !has_n13_format {
            return ConditionResult::False;
        }
        let dtm_segs = ctx.find_segments_with_qualifier("DTM", 0, "157");
        match dtm_segs.first() {
            Some(dtm) => {
                let value = dtm
                    .elements
                    .first()
                    .and_then(|e| e.get(1))
                    .map(|s| s.as_str())
                    .unwrap_or("");
                if value.len() >= 8 {
                    ConditionResult::from(&value[..8] < "20240101")
                } else {
                    ConditionResult::Unknown
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [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...
    fn evaluate_48(&self, ctx: &EvaluationContext) -> ConditionResult {
        const CODES: &[&str] = &[
            "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-9-004",
            "1-07-4-001",
        ];
        let lin_segments = ctx.find_segments("LIN");
        ConditionResult::from(lin_segments.iter().any(|s| {
            s.elements
                .get(2)
                .and_then(|e| e.first())
                .map_or(false, |v| CODES.contains(&v.as_str()))
        }))
    }

    /// [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...
    fn evaluate_49(&self, ctx: &EvaluationContext) -> ConditionResult {
        const CODES: &[&str] = &[
            "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-9-004",
            "1-07-4-001",
        ];
        let lin_segments = ctx.find_segments("LIN");
        ConditionResult::from(!lin_segments.iter().any(|s| {
            s.elements
                .get(2)
                .and_then(|e| e.first())
                .map_or(false, |v| CODES.contains(&v.as_str()))
        }))
    }

    /// [50] Wenn MP-ID aus RFF+Z56 mit MP-ID aus NAD+MS identisch ist
    fn evaluate_50(&self, ctx: &EvaluationContext) -> ConditionResult {
        let rff_segs = ctx.find_segments_with_qualifier("RFF", 0, "Z56");
        let nad_segs = ctx.find_segments_with_qualifier("NAD", 0, "MS");
        let rff_mp_id = rff_segs
            .first()
            .and_then(|s| s.elements.first())
            .and_then(|e| e.get(1))
            .map(|s| s.as_str());
        let nad_mp_id = nad_segs
            .first()
            .and_then(|s| s.elements.get(1))
            .and_then(|e| e.first())
            .map(|s| s.as_str());
        match (rff_mp_id, nad_mp_id) {
            (Some(rff), Some(nad)) if !rff.is_empty() && !nad.is_empty() => {
                ConditionResult::from(rff == nad)
            }
            _ => ConditionResult::Unknown,
        }
    }

    /// [51] Wenn BGM+Z54 vorhanden
    fn evaluate_51(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("BGM", 0, "Z54")
    }

    /// [52] Wenn BGM+Z54 nicht vorhanden
    fn evaluate_52(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.lacks_qualifier("BGM", 0, "Z54")
    }

    /// [53] Diese SG40 darf genau einmal in der SG36 angegeben werden
    // 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)
    fn evaluate_53(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Diese SG40 darf genau einmal in der SG36 angegeben werden
        // For each SG36 instance, verify SG40 appears exactly once as a child group
        let nav = match ctx.navigator() {
            Some(n) => n,
            None => return ConditionResult::Unknown,
        };
        let sg36_count = nav.group_instance_count(&["SG17", "SG36"]);
        if sg36_count == 0 {
            return ConditionResult::Unknown;
        }
        for i in 0..sg36_count {
            let sg40_count = nav.child_group_instance_count(&["SG17", "SG36"], i, "SG40");
            if sg40_count != 1 {
                return ConditionResult::False;
            }
        }
        ConditionResult::True
    }

    /// [64] Wenn der Zeitpunkt im DTM+157 DE2380 ≥ 01.01.2026, 00:00 Uhr gesetzlicher deutscher Zeit
    fn evaluate_64(&self, ctx: &EvaluationContext) -> ConditionResult {
        let dtm_segs = ctx.find_segments_with_qualifier("DTM", 0, "157");
        match dtm_segs.first() {
            Some(dtm) => {
                let value = dtm
                    .elements
                    .first()
                    .and_then(|e| e.get(1))
                    .map(|s| s.as_str())
                    .unwrap_or("");
                if value.len() >= 8 {
                    ConditionResult::from(&value[..8] >= "20260101")
                } else {
                    ConditionResult::Unknown
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [492] wenn MP-ID in NAD+MR aus Sparte Strom
    /// EXTERNAL: Requires context from outside the message.
    // 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)
    fn evaluate_492(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("recipient_is_strom")
    }

    /// [494] Das hier genannte Datum muss der Zeitpunkt sein, zu dem das Dokument erstellt wurde, oder ein Zeitpunkt, der davor liegt
    fn evaluate_494(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Das hier genannte Datum muss der Zeitpunkt sein, zu dem das Dokument
        // erstellt wurde, oder ein Zeitpunkt, der davor liegt. Informational annotation
        // about the semantic meaning of the date field — always applies unconditionally.
        ConditionResult::True
    }

    /// [495] Der Zeitpunkt muss ≤ dem Wert im DE2380 des DTM+137 sein
    // 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)
    fn evaluate_495(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Der Zeitpunkt (DTM+492 Betrachtungszeitintervall) muss <= DTM+137 (Nachrichtendatum) sein
        let dtm_137_segs = ctx.find_segments_with_qualifier("DTM", 0, "137");
        let dtm_137 = match dtm_137_segs.first() {
            Some(s) => s,
            None => return ConditionResult::Unknown,
        };
        let threshold = match dtm_137.elements.first().and_then(|e| e.get(1)) {
            Some(v) => v.clone(),
            None => return ConditionResult::Unknown,
        };
        ctx.dtm_le("492", &threshold)
    }

    /// [502] Hinweis: Preis in Euro je MWh
    fn evaluate_502(&self, _ctx: &EvaluationContext) -> ConditionResult {
        ConditionResult::True
    }

    /// [503] Hinweis: Hier ist immer der Wert 1000 einzutragen, da in DE5118 der Preis in €/MWh angegeben wird.
    fn evaluate_503(&self, _ctx: &EvaluationContext) -> ConditionResult {
        ConditionResult::True
    }

    /// [504] Hinweis: Dokumentennummer der PRICAT
    fn evaluate_504(&self, _ctx: &EvaluationContext) -> ConditionResult {
        ConditionResult::True
    }

    /// [511] Hinweis: 1. Der genannte Wert gehört nicht zum Intervall.  2. Wenn in dieser SG36 die letzte Ziffer von LIN DE7140 &gt;1, dann ist der Wert identisch mit dem Wert des DE6152 im RNG-Segment, in der...
    fn evaluate_511(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: informational annotation about RNG value semantics and ordering rules across Artikel-IDs
        ConditionResult::True
    }

    /// [512] Hinweis: Der genannte Wert gehört zum Intervall
    fn evaluate_512(&self, _ctx: &EvaluationContext) -> ConditionResult {
        ConditionResult::True
    }

    /// [513] Hinweis: Die zum Preis gehörende Einheit ist in der Codeliste definiert
    fn evaluate_513(&self, _ctx: &EvaluationContext) -> ConditionResult {
        ConditionResult::True
    }

    /// [519] Hinweis: Es darf nur eine Information im DE3148 übermittelt werden
    fn evaluate_519(&self, _ctx: &EvaluationContext) -> ConditionResult {
        ConditionResult::True
    }

    /// [520] Hinweis: Falls der Preis des Artikels gezont ist, ist diese SG40 so oft zu wiederholen, bis alle Preise zu diesem Artikel genannt sind
    fn evaluate_520(&self, _ctx: &EvaluationContext) -> ConditionResult {
        ConditionResult::True
    }

    /// [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...
    fn evaluate_521(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: informational annotation about RNG DE value relationships — one RNG must have value 0,
        // all others must equal DE6152 of another RNG for the same Artikel-ID
        ConditionResult::True
    }

    /// [902] Format: Möglicher Wert: ≥ 0
    fn evaluate_902(&self, _ctx: &EvaluationContext) -> ConditionResult {
        ConditionResult::True
    }

    /// [908] Format: Mögliche Werte: 1 bis n
    fn evaluate_908(&self, _ctx: &EvaluationContext) -> ConditionResult {
        ConditionResult::True
    }

    /// [909] Format: Mögliche Werte: 0 bis n
    // 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)
    fn evaluate_909(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Format: Mögliche Werte 0 bis n — numeric value must be >= 0
        // Applied to LIN DE1082 (Positionsnummer) which can start from 0
        let lin_segs = ctx.find_segments("LIN");
        if lin_segs.is_empty() {
            return ConditionResult::Unknown;
        }
        for seg in &lin_segs {
            let val = match seg.elements.first().and_then(|e| e.first()) {
                Some(v) => v,
                None => return ConditionResult::Unknown,
            };
            match validate_numeric(val, ">=", 0.0) {
                ConditionResult::False => return ConditionResult::False,
                ConditionResult::Unknown => return ConditionResult::Unknown,
                ConditionResult::True => {}
            }
        }
        ConditionResult::True
    }

    /// [911] Format: Mögliche Werte: 1 bis n, je Nachricht oder Segmentgruppe bei 1 beginnend und fortlaufend aufsteigend
    // 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)
    fn evaluate_911(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Format: Mögliche Werte 1 bis n, sequential per message/segment group starting at 1
        // Validates LIN DE1082 (Positionsnummer) is sequential starting from 1
        let lin_segs = ctx.find_segments("LIN");
        if lin_segs.is_empty() {
            return ConditionResult::Unknown;
        }
        let mut expected: u64 = 1;
        for seg in &lin_segs {
            let pos_str = match seg.elements.first().and_then(|e| e.first()) {
                Some(v) => v,
                None => return ConditionResult::Unknown,
            };
            let pos: u64 = match pos_str.parse() {
                Ok(n) => n,
                Err(_) => return ConditionResult::False,
            };
            if pos != expected {
                return ConditionResult::False;
            }
            expected += 1;
        }
        ConditionResult::True
    }

    /// [912] Format: max. 6 Nachkommastellen
    // 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)
    fn evaluate_912(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("PRI", 0, 1, |val| validate_max_decimal_places(val, 6))
    }

    /// [926] Format: Möglicher Wert: 0
    // 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)
    fn evaluate_926(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("QTY", 0, 1, |val| validate_numeric(val, "==", 0.0))
    }

    /// [929] Format: Möglicher Wert: 1000
    // 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)
    fn evaluate_929(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("QTY", 0, 1, |val| validate_numeric(val, "==", 1000.0))
    }

    /// [931] Format: ZZZ = +00
    // 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)
    fn evaluate_931(&self, ctx: &EvaluationContext) -> ConditionResult {
        // ZZZ = +00: timezone offset in DTM value must be +00
        // DTM format 303: YYYYMMDDHHMMzzz, timezone encoded as last part of elements[0][1]
        let dtm_segments = ctx.find_segments("DTM");
        for seg in &dtm_segments {
            if let Some(value) = seg.elements.first().and_then(|e| e.get(1)) {
                if !value.is_empty() {
                    // Timezone +00 appears at end of value string
                    if value.ends_with("+00") {
                        return ConditionResult::True;
                    } else {
                        return ConditionResult::False;
                    }
                }
            }
        }
        ConditionResult::Unknown
    }

    /// [932] Format: HHMM = 2200
    // 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)
    fn evaluate_932(&self, ctx: &EvaluationContext) -> ConditionResult {
        // HHMM = 2200: time value in DTM must be 2200
        // In DTM format 203 (YYYYMMDDHHMM) or 401 (HHMM), the time portion is HHMM
        let dtm_segments = ctx.find_segments("DTM");
        for seg in &dtm_segments {
            if let Some(value) = seg.elements.first().and_then(|e| e.get(1)) {
                let format_code = seg
                    .elements
                    .first()
                    .and_then(|e| e.get(2))
                    .map(|s| s.as_str())
                    .unwrap_or("");
                let time_part = match format_code {
                    "203" if value.len() >= 12 => &value[8..12],
                    "401" if value.len() >= 4 => &value[0..4],
                    _ if value.len() >= 12 => &value[8..12],
                    _ => continue,
                };
                if time_part == "2200" {
                    return ConditionResult::True;
                } else {
                    return ConditionResult::False;
                }
            }
        }
        ConditionResult::Unknown
    }

    /// [933] Format: HHMM = 2300
    // 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)
    fn evaluate_933(&self, ctx: &EvaluationContext) -> ConditionResult {
        // HHMM = 2300: time value in DTM must be 2300
        let dtm_segments = ctx.find_segments("DTM");
        for seg in &dtm_segments {
            if let Some(value) = seg.elements.first().and_then(|e| e.get(1)) {
                let format_code = seg
                    .elements
                    .first()
                    .and_then(|e| e.get(2))
                    .map(|s| s.as_str())
                    .unwrap_or("");
                let time_part = match format_code {
                    "203" if value.len() >= 12 => &value[8..12],
                    "401" if value.len() >= 4 => &value[0..4],
                    _ if value.len() >= 12 => &value[8..12],
                    _ => continue,
                };
                if time_part == "2300" {
                    return ConditionResult::True;
                } else {
                    return ConditionResult::False;
                }
            }
        }
        ConditionResult::Unknown
    }

    /// [937] Format: keine Nachkommastelle
    // 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)
    fn evaluate_937(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("QTY", 0, 1, |val| validate_max_decimal_places(val, 0))
    }

    /// [939] Format: Die Zeichenkette muss die Zeichen @ und . enthalten
    // 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)
    fn evaluate_939(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Email format: string must contain both '@' and '.'
        // Typically applies to COM segment (communication channel EM = email)
        let com_segments = ctx.find_segments("COM");
        for seg in &com_segments {
            // COM: elements[0][0] = communication address, elements[0][1] = channel code
            let channel = seg
                .elements
                .first()
                .and_then(|e| e.get(1))
                .map(|s| s.as_str())
                .unwrap_or("");
            if channel == "EM" {
                if let Some(address) = seg.elements.first().and_then(|e| e.first()) {
                    let contains_at = address.contains('@');
                    let contains_dot = address.contains('.');
                    return ConditionResult::from(contains_at && contains_dot);
                }
            }
        }
        // Fallback: check any COM value for @ and .
        for seg in &com_segments {
            if let Some(address) = seg.elements.first().and_then(|e| e.first()) {
                if !address.is_empty() {
                    return ConditionResult::from(address.contains('@') && address.contains('.'));
                }
            }
        }
        ConditionResult::Unknown
    }

    /// [940] Format: Die Zeichenkette muss mit dem Zeichen + beginnen und danach dürfen nur noch Ziffern folgen
    // 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)
    fn evaluate_940(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Phone number format: must start with '+' followed only by digits
        // Typically applies to COM segment (TEL/FAX channel)
        let com_segments = ctx.find_segments("COM");
        for seg in &com_segments {
            let channel = seg
                .elements
                .first()
                .and_then(|e| e.get(1))
                .map(|s| s.as_str())
                .unwrap_or("");
            if matches!(channel, "TE" | "FX" | "AJ") {
                if let Some(number) = seg.elements.first().and_then(|e| e.first()) {
                    if !number.is_empty() {
                        let valid = number.starts_with('+')
                            && number.len() > 1
                            && number[1..].chars().all(|c| c.is_ascii_digit());
                        return ConditionResult::from(valid);
                    }
                }
            }
        }
        // Fallback: check any COM value for +digit format
        for seg in &com_segments {
            if let Some(number) = seg.elements.first().and_then(|e| e.first()) {
                if !number.is_empty() {
                    let valid = number.starts_with('+')
                        && number.len() > 1
                        && number[1..].chars().all(|c| c.is_ascii_digit());
                    return ConditionResult::from(valid);
                }
            }
        }
        ConditionResult::Unknown
    }

    /// [941] Format: Artikelnummer
    // 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)
    fn evaluate_941(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("PIA", 1, 0, |val| {
            validate_artikel_pattern(val, &[1, 2, 1, 3])
        })
    }

    /// [942] Format: n1-n2-n1-n3
    fn evaluate_942(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("PIA", 1, 0, |val| {
            validate_artikel_pattern(val, &[1, 2, 1, 3])
        })
    }

    /// [946] Format: max. 11 Nachkommastellen
    // 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)
    fn evaluate_946(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("PRI", 0, 1, |val| validate_max_decimal_places(val, 11))
    }

    /// [948] Format: n1-n2-n1-n8-n2
    fn evaluate_948(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("PIA", 1, 0, |val| {
            validate_artikel_pattern(val, &[1, 2, 1, 8, 2])
        })
    }

    /// [949] Format: n1-n2-n1-n8-n2-n1
    fn evaluate_949(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("PIA", 1, 0, |val| {
            validate_artikel_pattern(val, &[1, 2, 1, 8, 2, 1])
        })
    }

    /// [957] Format: n1-n2-n1-n8
    fn evaluate_957(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("PIA", 1, 0, |val| {
            validate_artikel_pattern(val, &[1, 2, 1, 8])
        })
    }

    /// [959] Format: n13-n2
    // 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)
    fn evaluate_959(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("PIA", 1, 0, |val| validate_artikel_pattern(val, &[13, 2]))
    }

    /// [968] Format: Möglicher Wert: ≤ 0
    // 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)
    fn evaluate_968(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("PRI", 0, 1, |val| validate_numeric(val, "<=", 0.0))
    }
}