automapper-validation 0.1.62

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
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
// <auto-generated>
// Generated by automapper-generator generate-conditions
// AHB: xml-migs-and-ahbs/FV2504/QUOTES_AHB_1_0_Fehlerkorrektur_20241213.xml
// Generated: 2026-03-12T10:21:41Z
// </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 QUOTES FV2504.
pub struct QuotesConditionEvaluatorFV2504 {
    // External condition IDs that require runtime context.
    external_conditions: std::collections::HashSet<u32>,
}

impl Default for QuotesConditionEvaluatorFV2504 {
    fn default() -> Self {
        let mut external_conditions = std::collections::HashSet::new();
        external_conditions.insert(1);
        external_conditions.insert(4);
        external_conditions.insert(13);
        external_conditions.insert(29);
        external_conditions.insert(31);
        external_conditions.insert(39);
        external_conditions.insert(44);
        external_conditions.insert(54);
        external_conditions.insert(56);
        external_conditions.insert(57);
        external_conditions.insert(58);
        external_conditions.insert(59);
        external_conditions.insert(60);
        external_conditions.insert(61);
        external_conditions.insert(62);
        external_conditions.insert(63);
        external_conditions.insert(69);
        external_conditions.insert(70);
        external_conditions.insert(71);
        external_conditions.insert(74);
        external_conditions.insert(75);
        external_conditions.insert(77);
        external_conditions.insert(78);
        external_conditions.insert(492);
        external_conditions.insert(493);
        external_conditions.insert(494);
        external_conditions.insert(2066);
        Self {
            external_conditions,
        }
    }
}

impl ConditionEvaluator for QuotesConditionEvaluatorFV2504 {
    fn message_type(&self) -> &str {
        "QUOTES"
    }

    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),
            8 => self.evaluate_8(ctx),
            9 => self.evaluate_9(ctx),
            10 => self.evaluate_10(ctx),
            11 => self.evaluate_11(ctx),
            12 => self.evaluate_12(ctx),
            13 => self.evaluate_13(ctx),
            15 => self.evaluate_15(ctx),
            16 => self.evaluate_16(ctx),
            17 => self.evaluate_17(ctx),
            18 => self.evaluate_18(ctx),
            20 => self.evaluate_20(ctx),
            21 => self.evaluate_21(ctx),
            22 => self.evaluate_22(ctx),
            25 => self.evaluate_25(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),
            39 => self.evaluate_39(ctx),
            44 => self.evaluate_44(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),
            56 => self.evaluate_56(ctx),
            57 => self.evaluate_57(ctx),
            58 => self.evaluate_58(ctx),
            59 => self.evaluate_59(ctx),
            60 => self.evaluate_60(ctx),
            61 => self.evaluate_61(ctx),
            62 => self.evaluate_62(ctx),
            63 => self.evaluate_63(ctx),
            65 => self.evaluate_65(ctx),
            66 => self.evaluate_66(ctx),
            67 => self.evaluate_67(ctx),
            68 => self.evaluate_68(ctx),
            69 => self.evaluate_69(ctx),
            70 => self.evaluate_70(ctx),
            71 => self.evaluate_71(ctx),
            72 => self.evaluate_72(ctx),
            73 => self.evaluate_73(ctx),
            74 => self.evaluate_74(ctx),
            75 => self.evaluate_75(ctx),
            77 => self.evaluate_77(ctx),
            78 => self.evaluate_78(ctx),
            79 => self.evaluate_79(ctx),
            80 => self.evaluate_80(ctx),
            81 => self.evaluate_81(ctx),
            82 => self.evaluate_82(ctx),
            83 => self.evaluate_83(ctx),
            84 => self.evaluate_84(ctx),
            85 => self.evaluate_85(ctx),
            86 => self.evaluate_86(ctx),
            87 => self.evaluate_87(ctx),
            88 => self.evaluate_88(ctx),
            490 => self.evaluate_490(ctx),
            491 => self.evaluate_491(ctx),
            492 => self.evaluate_492(ctx),
            493 => self.evaluate_493(ctx),
            494 => self.evaluate_494(ctx),
            500 => self.evaluate_500(ctx),
            501 => self.evaluate_501(ctx),
            502 => self.evaluate_502(ctx),
            503 => self.evaluate_503(ctx),
            504 => self.evaluate_504(ctx),
            505 => self.evaluate_505(ctx),
            506 => self.evaluate_506(ctx),
            507 => self.evaluate_507(ctx),
            511 => self.evaluate_511(ctx),
            512 => self.evaluate_512(ctx),
            513 => self.evaluate_513(ctx),
            514 => self.evaluate_514(ctx),
            516 => self.evaluate_516(ctx),
            903 => self.evaluate_903(ctx),
            906 => self.evaluate_906(ctx),
            908 => self.evaluate_908(ctx),
            911 => self.evaluate_911(ctx),
            912 => self.evaluate_912(ctx),
            914 => self.evaluate_914(ctx),
            931 => self.evaluate_931(ctx),
            932 => self.evaluate_932(ctx),
            933 => self.evaluate_933(ctx),
            934 => self.evaluate_934(ctx),
            935 => self.evaluate_935(ctx),
            939 => self.evaluate_939(ctx),
            940 => self.evaluate_940(ctx),
            942 => self.evaluate_942(ctx),
            950 => self.evaluate_950(ctx),
            951 => self.evaluate_951(ctx),
            960 => self.evaluate_960(ctx),
            961 => self.evaluate_961(ctx),
            962 => self.evaluate_962(ctx),
            2042 => self.evaluate_2042(ctx),
            2060 => self.evaluate_2060(ctx),
            2061 => self.evaluate_2061(ctx),
            2062 => self.evaluate_2062(ctx),
            2063 => self.evaluate_2063(ctx),
            2064 => self.evaluate_2064(ctx),
            2066 => self.evaluate_2066(ctx),
            2068 => self.evaluate_2068(ctx),
            2069 => self.evaluate_2069(ctx),
            2070 => self.evaluate_2070(ctx),
            2071 => self.evaluate_2071(ctx),
            2072 => self.evaluate_2072(ctx),
            2073 => self.evaluate_2073(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
                | 8
                | 9
                | 10
                | 11
                | 12
                | 13
                | 15
                | 16
                | 17
                | 18
                | 20
                | 21
                | 22
                | 25
                | 26
                | 27
                | 28
                | 29
                | 30
                | 31
                | 39
                | 44
                | 49
                | 50
                | 51
                | 52
                | 53
                | 54
                | 55
                | 56
                | 57
                | 58
                | 59
                | 60
                | 61
                | 62
                | 63
                | 65
                | 66
                | 67
                | 68
                | 69
                | 70
                | 71
                | 72
                | 73
                | 74
                | 75
                | 77
                | 78
                | 79
                | 80
                | 81
                | 82
                | 83
                | 84
                | 85
                | 86
                | 87
                | 88
                | 490
                | 491
                | 492
                | 493
                | 494
                | 500
                | 501
                | 502
                | 503
                | 504
                | 505
                | 506
                | 507
                | 511
                | 512
                | 513
                | 514
                | 516
                | 903
                | 906
                | 908
                | 911
                | 912
                | 914
                | 931
                | 932
                | 933
                | 934
                | 935
                | 939
                | 940
                | 942
                | 950
                | 951
                | 960
                | 961
                | 962
                | 2042
                | 2060
                | 2061
                | 2062
                | 2063
                | 2064
                | 2066
                | 2068
                | 2069
                | 2070
                | 2071
                | 2072
                | 2073
        )
    }
}

impl QuotesConditionEvaluatorFV2504 {
    /// [31] Es sind nur die Artikelnummern erlaubt, die in der Codeliste der Artikelnummern des BDEW mit dem entsprechenden Prüfidentifikator versehen sind.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_31(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("artikel_number_in_bdew_codelist")
    }

    /// [56] Wenn in LOC+172 DE3225 (Meldepunkt) die ID einer Messlokation angegeben ist.
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Condition asks whether the ID in LOC+172 DE3225 (elements[1][0]) belongs to a Messlokation. While Messlokation IDs have a known 33-char format in Germany, the semantic type assignment (Messlokation vs other location types) ultimately requires external business context or a type registry lookup. Marked external. (medium confidence)
    fn evaluate_56(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("loc_172_id_is_messlokation")
    }

    /// [57] Wenn in LOC+172 DE3225 (Meldepunkt) die ID einer Netzlokation angegeben ist.
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Condition asks whether the ID in LOC+172 DE3225 (elements[1][0]) belongs to a Netzlokation. The ID type cannot be determined from EDIFACT message content alone — requires external type registry or format-based classification beyond the available validators. (medium confidence)
    fn evaluate_57(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("loc_172_id_is_netzlokation")
    }

    /// [58] Wenn in LOC+172 DE3225 (Meldepunkt) die ID einer Steuerbaren Ressource angegeben ist.
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Condition asks whether the ID in LOC+172 DE3225 (elements[1][0]) belongs to a Steuerbare Ressource. Same reasoning as [56] and [57] — semantic type assignment requires external business context. (medium confidence)
    fn evaluate_58(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("loc_172_id_is_steuerbare_ressource")
    }

    /// [59] Es sind nur die Konfigurations-Produkte erlaubt, die in der Codeliste der Konfigurationen im Kapitel 4.1 „Konfigurationsprodukte Schaltzeitdefinition“ enthalten sind.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_59(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external
            .evaluate("konfiguration_in_kapitel_4_1_codelist")
    }

    /// [60] Es sind nur die Konfigurations-Produkte erlaubt, die in der Codeliste der Konfigurationen im Kapitel 4.2 „Konfigurationsprodukte Leistungskurvendefinition“ enthalten sind.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_60(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("config_product_leistungskurve")
    }

    /// [61] Es sind nur die Konfigurations-Produkte erlaubt, die in der Codeliste der Konfigurationen im Kapitel 4.3 „Konfigurationsprodukte Ad-hoc-Steuerkanal“ enthalten sind.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_61(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("config_product_adhoc_steuerkanal")
    }

    /// [62] Es sind nur die Messprodukte erlaubt, die in der Codeliste der Konfigurationen im Kapitel 4.5 „Messprodukte für Werte nach Typ 2 aus Backend für LF und NB“ enthalten sind.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_62(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("messprodukts_typ2_backend_lf_nb")
    }

    /// [63] Es sind nur die Messprodukte erlaubt, die in der Codeliste der Konfigurationen im Kapitel 4.4 „Messprodukte mit Konfigurationserlaubnis für Werte nach Typ 2 aus SMGW“ enthalten sind.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_63(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("messprodukts_typ2_smgw")
    }

    /// [69] Es sind nur Werte aus der EDI@Energy Codeliste der Artikelnummern und Artikel-ID erlaubt, die im Kapitel 3.5 "Abrechnung Messstellenbetrieb für die Sparte Strom" genannt sind.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_69(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external
            .evaluate("artikel_id_abrechnung_messstellenbetrieb_strom")
    }

    /// [70] Es sind nur die Messprodukt-Position-Codes erlaubt, die in der Codeliste der Konfigurationen im Kapitel 4.7 „Art der Werte für Messprodukte nach Typ 2“ enthalten sind.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_70(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external
            .evaluate("messprodukt_position_code_valid_typ2")
    }

    /// [490] wenn Wert in diesem DE, an der Stelle CCYYMMDDHHMM ein Zeitpunkt aus dem angegeben Zeitraum der Tabelle Kapitel 3.5 „Übersicht gesetzliche deutsche Sommerzeit (MESZ)“ der Spalten: „Sommerzei...
    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 CCYYMMDDHHMM ein Zeitpunkt aus dem angegeben Zeitraum der Tabelle Kapitel 3.6 „Übersicht gesetzliche deutsche Zeit (MEZ)“ der Spalten: „Winterzeit (MEZ)...
    fn evaluate_491(&self, ctx: &EvaluationContext) -> ConditionResult {
        match ctx.resolved_value {
            Some(val) => is_mez_utc(val),
            None => ConditionResult::False,
        }
    }

    /// [961] Format: SR-ID
    // REVIEW: Format: SR-ID — 11-digit Luhn check digit number. In QUOTES context, Steuerbare Ressource IDs typically appear in LOC+Z19 at elements[1][0]. validate_sr_id checks 11 digits with Luhn validation. Medium confidence because QUOTES segment structure may differ from UTILMD. (medium confidence)
    fn evaluate_961(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check_qualified("LOC", 0, "Z19", 1, 0, validate_sr_id)
    }

    /// [2066] Diese SG28 ist so oft zu wiederholen, wie zu den unterschiedlichen Messprodukt-Position-Codes zu dem innerhalb derselben SG27 LIN im PIA+5 DE7140 (Erforderliches Produkt Konfigurationserlaubnis fü...
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_2066(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external
            .evaluate("sg28_repetition_count_for_schwellwert_produkt")
    }

    /// [1] Wenn Position nicht angeboten werden kann, weil rechtliche Regelungen oder Rechte Dritter dem entgegenstehen
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_1(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("position_legally_blocked")
    }

    /// [2] Wenn in derselben SG27 LIN IMD DE7081 (Produkt-/Leistungsbeschreibung) mit Code Z09 (Kann nicht angeboten werden) nicht vorhanden.
    // REVIEW: Negates presence of IMD with DE7081=Z09 (Kann nicht angeboten werden) at elements[1][0] in any SG27 group instance. 'nicht vorhanden' means condition is True when Z09 is absent. any_group_has_qualifier falls back to message-wide if no group navigator is available. (medium confidence)
    fn evaluate_2(&self, ctx: &EvaluationContext) -> ConditionResult {
        match ctx.any_group_has_qualifier("IMD", 1, "Z09", &["SG27"]) {
            ConditionResult::True => ConditionResult::False,
            ConditionResult::False => ConditionResult::True,
            ConditionResult::Unknown => ConditionResult::Unknown,
        }
    }

    /// [3] Wenn CCI+++Z64 vorhanden ist
    fn evaluate_3(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("CCI", 2, "Z64")
    }

    /// [4] Wenn am Gerät vorhanden und abweichend von Gerätenummer
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_4(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external
            .evaluate("device_attribute_differs_from_device_number")
    }

    /// [5] Wenn in derselben SG27 LIN die Artikelnummer 9990001000649 vorhanden ist
    // REVIEW: Checks if any SG27 group has LIN with article number 9990001000649 at elements[2][0] (C212 item number identification, first component). LIN is the entry segment of SG27 so each rep has exactly one LIN. (medium confidence)
    fn evaluate_5(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("LIN", 2, "9990001000649", &["SG27"])
    }

    /// [8] Wenn SG28 CCI+++E13 CAV+EHZ vorhanden
    // REVIEW: CCI+++E13 maps to elements[2][0]=E13; CAV+EHZ maps to elements[0][0]=EHZ. Checks that in the same SG28 group instance, CCI with characteristic code E13 AND CAV with code EHZ both occur. Group path SG28 may need parent prefix depending on MIG structure. (medium confidence)
    fn evaluate_8(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_co_occurrence("CCI", 2, &["E13"], "CAV", 0, 0, &["EHZ"], &["SG28"])
    }

    /// [9] Wenn in derselben SG27 LIN die Artikelnummer 9990001000657 vorhanden ist
    // REVIEW: Checks if any SG27 group has LIN with article number 9990001000657 at elements[2][0] (C212 first component). Same pattern as condition 5. (medium confidence)
    fn evaluate_9(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("LIN", 2, "9990001000657", &["SG27"])
    }

    /// [10] Wenn SG28 CAV+MIW/MPW/MBW vorhanden
    fn evaluate_10(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_any_qualifier("CAV", 0, &["MIW", "MPW", "MBW"], &["SG28"])
    }

    /// [11] Wenn in derselben SG27 LIN die Artikelnummer 9990001000665 vorhanden ist
    // REVIEW: Checks if any SG27 group has LIN with article number 9990001000665 at elements[2][0]. Same pattern as condition 5. (medium confidence)
    fn evaluate_11(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("LIN", 2, "9990001000665", &["SG27"])
    }

    /// [12] Wenn in derselben SG27 LIN die Artikelnummer 9990001000673 vorhanden ist
    // REVIEW: Checks if any SG27 group has LIN with article number 9990001000673 at elements[2][0]. Same pattern as condition 5. (medium confidence)
    fn evaluate_12(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("LIN", 2, "9990001000673", &["SG27"])
    }

    /// [13] Wenn am Gerät vorhanden
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_13(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("device_attribute_present")
    }

    /// [15] Wenn in derselben SG27 LIN die Artikelnummer 9990001000772 vorhanden ist
    // REVIEW: Checks if any SG27 group has LIN with article number 9990001000772 at elements[2][0]. Same pattern as condition 5. (medium confidence)
    fn evaluate_15(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("LIN", 2, "9990001000772", &["SG27"])
    }

    /// [16] Wenn in derselben SG27 LIN die Artikelnummer 9990001000780 vorhanden ist
    // REVIEW: Checks if any SG27 group has LIN with article number 9990001000780 at elements[2][0]. Same pattern as condition 5. (medium confidence)
    fn evaluate_16(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("LIN", 2, "9990001000780", &["SG27"])
    }

    /// [17] Wenn das Angebot per REQOTE angefragt wurde
    // REVIEW: A QUOTES message triggered by a REQOTE contains a reference RFF+AAV in SG1 (Nachrichtennummer der Anfrage, qualifier AAV at elements[0][0]). Presence of RFF+AAV indicates the quote was requested via REQOTE. (medium confidence)
    fn evaluate_17(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("RFF", 0, "AAV")
    }

    /// [18] Wenn Angebot mehrere Marktlokationen abdeckt, an welchen der identische Anschlussnutzer vorhanden ist und deren messtechnische Einordnung iMS ist (Marktlokation aus SG11 LOC+172 und alle Marktlokat...
    // REVIEW: RFF+Z18 ('Referenz auf ID weiterer Marktlokationen') is the direct EDIFACT indicator that additional market locations are covered, which is the core structural requirement. However, the additional qualifiers — identical Anschlussnutzer and messtechnische Einordnung iMS — are business attributes about the referenced locations not determinable from message content alone. The RFF+Z18 check is the best message-derivable approximation. (medium confidence)
    fn evaluate_18(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Check if offer references additional market locations via RFF+Z18
        // RFF+Z18 = 'Referenz auf ID weiterer Marktlokationen' — presence indicates multiple locations covered
        // Note: the 'identical connection user' and 'iMS classification' sub-conditions require external context
        ctx.has_qualifier("RFF", 0, "Z18")
    }

    /// [20] Wenn IMD++Z33 vorhanden
    fn evaluate_20(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("IMD", 1, "Z33")
    }

    /// [21] Wenn IMD++Z34 vorhanden
    fn evaluate_21(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("IMD", 1, "Z34")
    }

    /// [22] Wenn CCI+++Z75 vorhanden ist
    fn evaluate_22(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("CCI", 2, "Z75")
    }

    /// [25] Wenn SG28 CCI+++E13 CAV+MME vorhanden
    fn evaluate_25(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_co_occurrence("CCI", 2, &["E13"], "CAV", 0, 0, &["MME"], &["SG28"])
    }

    /// [26] Wenn DTM+203 nicht vorhanden
    fn evaluate_26(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.lacks_qualifier("DTM", 0, "203")
    }

    /// [27] Wenn DTM+469 nicht vorhanden
    fn evaluate_27(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.lacks_qualifier("DTM", 0, "469")
    }

    /// [28] Wenn RFF+AAV vorhanden
    fn evaluate_28(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("RFF", 0, "AAV")
    }

    /// [29] Wenn DTM+469 in Anfrage (REQOTE) vorhanden war
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_29(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("reqote_had_dtm_469")
    }

    /// [30] Wenn SG27 IMD+Z09 vorhanden
    fn evaluate_30(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("IMD", 0, "Z09", &["SG27"])
    }

    /// [39] MP-ID nur aus Sparte Strom
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_39(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("mp_id_is_strom")
    }

    /// [44] Wenn MSBA nicht Eigentümer des Gerätes/der Geräte ist
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_44(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("msba_is_not_device_owner")
    }

    /// [49] Wenn SG27 LIN++Z64 (Erforderliches Produkt Schaltzeitdefinitionen) vorhanden
    fn evaluate_49(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("LIN", 1, "Z64", &["SG27"])
    }

    /// [50] Wenn SG27 LIN++Z65 (Erforderliches Produkt Leistungskurvendefinitionen) vorhanden
    fn evaluate_50(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("LIN", 1, "Z65", &["SG27"])
    }

    /// [51] Wenn SG27 LIN++Z66 (Erforderliches Produkt Ad-hoc-Steuerkanal) vorhanden
    fn evaluate_51(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("LIN", 1, "Z66", &["SG27"])
    }

    /// [52] Wenn SG27 LIN++Z67 (Erforderliches Messprodukt für Werte nach Typ 2 aus Backend) vorhanden
    fn evaluate_52(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("LIN", 1, "Z67")
    }

    /// [53] Wenn SG27 LIN++Z68 (Erforderliches Produkt Konfigurationserlaubnis für Werte nach Typ2 aus SMGW) vorhanden
    fn evaluate_53(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("LIN", 1, "Z68")
    }

    /// [54] Wenn in der Anfrage zum Angebot einer Konfiguration vorhanden
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_54(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("configuration_in_request")
    }

    /// [55] Wenn in LOC+172 DE3225 (Meldepunkt) die ID einer Marktlokation angegeben ist.
    fn evaluate_55(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Wenn in LOC+172 DE3225 (Meldepunkt) die ID einer Marktlokation angegeben ist.
        // LOC elements[0][0] == "172" (qualifier), elements[1][0] == DE3225 (Identifikator)
        let locs = ctx.find_segments_with_qualifier("LOC", 0, "172");
        match locs
            .first()
            .and_then(|s| s.elements.get(1))
            .and_then(|e| e.first())
        {
            Some(val) => validate_malo_id(val),
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [65] Wenn DTM+203 (Ausführungsdatum) im DE2380 &lt; 202312312300?+00
    // REVIEW: DTM+203 DE2380 is at elements[0][1]. Lexicographic comparison works for YYYYMMDDHHMI+ZZ format since all values use the same timezone offset and format. The EDIFACT escape `?+` in the threshold represents a literal `+`, giving the threshold string "202312312300+00". (medium confidence)
    fn evaluate_65(&self, ctx: &EvaluationContext) -> ConditionResult {
        let segs = ctx.find_segments_with_qualifier("DTM", 0, "203");
        match segs.first() {
            Some(dtm) => {
                match dtm
                    .elements
                    .first()
                    .and_then(|e| e.get(1))
                    .map(|s| s.as_str())
                {
                    Some(value) if !value.is_empty() => {
                        ConditionResult::from(value < "202312312300+00")
                    }
                    _ => ConditionResult::Unknown,
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [66] Wenn DTM+469 (Beginn zum (nächstmöglichen Termin)) im DE2380 &lt; 202312312300?+00
    // REVIEW: DTM+469 DE2380 is at elements[0][1]. Same lexicographic comparison as condition 65, applied to the Beginn zum nächstmöglichen Termin qualifier 469. (medium confidence)
    fn evaluate_66(&self, ctx: &EvaluationContext) -> ConditionResult {
        let segs = ctx.find_segments_with_qualifier("DTM", 0, "469");
        match segs.first() {
            Some(dtm) => {
                match dtm
                    .elements
                    .first()
                    .and_then(|e| e.get(1))
                    .map(|s| s.as_str())
                {
                    Some(value) if !value.is_empty() => {
                        ConditionResult::from(value < "202312312300+00")
                    }
                    _ => ConditionResult::Unknown,
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [67] Wenn DTM+203 (Ausführungsdatum) im DE2380 ≥ 202312312300?+00
    // REVIEW: DTM+203 DE2380 is at elements[0][1]. Logical complement of condition 65 — True when Ausführungsdatum >= 2023-12-31 23:00 UTC. Lexicographic comparison is valid for this date format. (medium confidence)
    fn evaluate_67(&self, ctx: &EvaluationContext) -> ConditionResult {
        let segs = ctx.find_segments_with_qualifier("DTM", 0, "203");
        match segs.first() {
            Some(dtm) => {
                match dtm
                    .elements
                    .first()
                    .and_then(|e| e.get(1))
                    .map(|s| s.as_str())
                {
                    Some(value) if !value.is_empty() => {
                        ConditionResult::from(value >= "202312312300+00")
                    }
                    _ => ConditionResult::Unknown,
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [68] Wenn DTM+469 (Beginn zum (nächstmöglichen Termin)) im DE2380 ≥ 202312312300?+00
    // REVIEW: DTM+469 DE2380 (elements[0][1]) compared lexicographically — works for ISO datetime strings with fixed-width format. EDIFACT ?+ escape resolves to literal + in parsed value. (medium confidence)
    fn evaluate_68(&self, ctx: &EvaluationContext) -> ConditionResult {
        let segs = ctx.find_segments_with_qualifier("DTM", 0, "469");
        if segs.is_empty() {
            return ConditionResult::Unknown;
        }
        for seg in segs {
            let val = seg
                .elements
                .get(0)
                .and_then(|e| e.get(1))
                .map(|s| s.as_str())
                .unwrap_or("");
            if val >= "202312312300+00" {
                return ConditionResult::True;
            }
        }
        ConditionResult::False
    }

    /// [71] Wenn innerhalb derselben SG27 LIN im PIA+5 DE7140 (Erforderliches Produkt Konfigurationserlaubnis für Werte nach Typ 2 aus SMGW) ein Produkt angegeben ist, das in der Codeliste der Konfigurationen...
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_71(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("pia5_product_is_threshold_trigger")
    }

    /// [72] wenn im DE3155 in demselben COM der Code EM vorhanden ist
    fn evaluate_72(&self, ctx: &EvaluationContext) -> ConditionResult {
        let segs = ctx.find_segments("COM");
        if segs.is_empty() {
            return ConditionResult::Unknown;
        }
        ConditionResult::from(segs.iter().any(|seg| {
            seg.elements
                .first()
                .and_then(|e| e.get(1))
                .is_some_and(|v| v == "EM")
        }))
    }

    /// [73] wenn im DE3155 in demselben COM der Code TE / FX / AJ / AL vorhanden ist
    fn evaluate_73(&self, ctx: &EvaluationContext) -> ConditionResult {
        let segs = ctx.find_segments("COM");
        if segs.is_empty() {
            return ConditionResult::Unknown;
        }
        ConditionResult::from(segs.iter().any(|seg| {
            seg.elements
                .first()
                .and_then(|e| e.get(1))
                .is_some_and(|v| matches!(v.as_str(), "TE" | "FX" | "AJ" | "AL"))
        }))
    }

    /// [74] Es sind nur die Messprodukte erlaubt, die in der Codeliste der Konfigurationen im Kapitel 4.6.1 "Werte nach Typ 2 aus Backend" enthalten sind.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_74(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("product_in_typ2_backend_codelist")
    }

    /// [75] Es sind nur die Messprodukte erlaubt, die in der Codeliste der Konfigurationen im Kapitel 4.6.2 "Werte nach Typ 2 aus SMGW" enthalten sind.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_75(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("product_in_typ2_smgw_codelist")
    }

    /// [77] Wenn in der Anfrage nach Werten ein Messprodukt enthalten war, das in der Codeliste der Konfigurationen im Kapitel 4.6.1 "Werte nach Typ 2 aus Backend" enthalten ist.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_77(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external
            .evaluate("request_contained_typ2_backend_product")
    }

    /// [78] Wenn in der Anfrage nach Werten ein Messprodukt enthalten war, das in der Codeliste der Konfigurationen im Kapitel 4.6.2 "Werte nach Typ 2 aus SMWG" enthalten ist.
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_78(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("request_contained_typ2_smgw_product")
    }

    /// [79] Wenn IMD DE7081 (Produkt-/Leistungsbeschreibung) mit Wert Z07 (Kauf) vorhanden.
    fn evaluate_79(&self, ctx: &EvaluationContext) -> ConditionResult {
        let segs = ctx.find_segments("IMD");
        if segs.is_empty() {
            return ConditionResult::Unknown;
        }
        ConditionResult::from(segs.iter().any(|seg| {
            seg.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z07")
        }))
    }

    /// [80] Wenn IMD DE7081 (Produkt-/Leistungsbeschreibung) mit Wert Z08 (Nutzungsüberlassung) vorhanden.
    fn evaluate_80(&self, ctx: &EvaluationContext) -> ConditionResult {
        let segs = ctx.find_segments("IMD");
        if segs.is_empty() {
            return ConditionResult::Unknown;
        }
        ConditionResult::from(segs.iter().any(|seg| {
            seg.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z08")
        }))
    }

    /// [81] Wenn IMD DE7081 (Produkt-/Leistungsbeschreibung) mit Wert Z33 (Angebot auf Basis Preisblatt) vorhanden.
    fn evaluate_81(&self, ctx: &EvaluationContext) -> ConditionResult {
        let segs = ctx.find_segments("IMD");
        if segs.is_empty() {
            return ConditionResult::Unknown;
        }
        ConditionResult::from(segs.iter().any(|seg| {
            seg.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z33")
        }))
    }

    /// [82] Wenn IMD DE7081 (Produkt-/Leistungsbeschreibung) mit Wert Z34 (Individuelles Angebot) vorhanden.
    fn evaluate_82(&self, ctx: &EvaluationContext) -> ConditionResult {
        let segs = ctx.find_segments("IMD");
        if segs.is_empty() {
            return ConditionResult::Unknown;
        }
        ConditionResult::from(segs.iter().any(|seg| {
            seg.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z34")
        }))
    }

    /// [83] Wenn in derselben SG27 LIN ein PIA+Z02 (Artikel-ID) mit einer Artikel-ID im DE7140 bei der die letzten beiden Stellen mit dem Wert "01" (Kosten für das Einrichten des Messprodukts) vorhanden ist.
    // REVIEW: PIA+Z02 where elements[0][0]=="Z02" (Artikel-ID qualifier) and elements[1][0] ends with "01" (Kosten für Einrichten). Group-scoped to SG27 but falls back to message-wide search; medium confidence due to lack of SG27 navigator API for flat groups. (medium confidence)
    fn evaluate_83(&self, ctx: &EvaluationContext) -> ConditionResult {
        let segs = ctx.find_segments("PIA");
        if segs.is_empty() {
            return ConditionResult::Unknown;
        }
        ConditionResult::from(segs.iter().any(|seg| {
            let is_z02 = seg
                .elements
                .first()
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z02");
            let ends_with_01 = seg
                .elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v.ends_with("01"));
            is_z02 && ends_with_01
        }))
    }

    /// [84] Wenn in derselben SG27 LIN ein PIA+Z02 (Artikel-ID) mit einer Artikel-ID im DE7140 bei der die letzten beiden Stellen mit dem Wert "02" (Kosten für den Betrieb des Messprodukts) vorhanden ist.
    // REVIEW: Checks for PIA+Z02 where DE7140 (elements[1][0]) ends with '02' (Betriebskosten). Falls back to message-wide search since group-scoped navigator API has no direct find_segments_in_group for top-level SG27 — semantically equivalent for this condition. (medium confidence)
    fn evaluate_84(&self, ctx: &EvaluationContext) -> ConditionResult {
        let pias = ctx.find_segments_with_qualifier("PIA", 0, "Z02");
        ConditionResult::from(pias.iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .map(|v| v.ends_with("02"))
                .unwrap_or(false)
        }))
    }

    /// [85] Wenn in derselben SG27 LIN ein PIA+Z02 (Artikel-ID) mit einer Artikel-ID im DE7140 bei der die letzten beiden Stellen mit dem Wert "03" (Kosten für die anfallenden Transaktionen des Messprodukts) ...
    // REVIEW: Checks for PIA+Z02 where DE7140 (elements[1][0]) ends with '03' (Transaktionskosten). Same pattern as condition 84. (medium confidence)
    fn evaluate_85(&self, ctx: &EvaluationContext) -> ConditionResult {
        let pias = ctx.find_segments_with_qualifier("PIA", 0, "Z02");
        ConditionResult::from(pias.iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .map(|v| v.ends_with("03"))
                .unwrap_or(false)
        }))
    }

    /// [86] Wenn in derselben SG31 PRI (Preisangabe zur Position) das DE5387 mit dem Wert Z01 (Einrichtungspreis) vorhanden ist.
    fn evaluate_86(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("PRI", 0, "Z01", &["SG31"])
    }

    /// [87] Wenn in derselben SG31 PRI (Preisangabe zur Position) das DE5387 mit dem Wert Z02 (Transaktionspreis) vorhanden ist.
    fn evaluate_87(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("PRI", 0, "Z02", &["SG31"])
    }

    /// [88] Wenn in derselben SG31 PRI (Preisangabe zur Position) das DE5387 mit dem Wert Z03 (Betriebspreis) vorhanden ist.
    fn evaluate_88(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("PRI", 0, "Z03", &["SG31"])
    }

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

    /// [493] wenn MP-ID in NAD+MR aus Sparte Gas
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_493(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("recipient_is_gas_sector")
    }

    /// [494] Das hier genannte Datum muss der Zeitpunkt sein, zu dem das Dokument erstellt wurde, oder ein Zeitpunkt, der davor liegt.
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Validating that a date is the document creation date or earlier requires knowing the actual current/creation timestamp at validation time. This is a temporal constraint that depends on runtime context outside the message. (medium confidence)
    fn evaluate_494(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("document_date_is_creation_or_past")
    }

    /// [500] Hinweis: Angabe eines technischen Ansprechpartners für die Geräteübernahme
    fn evaluate_500(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Angabe eines technischen Ansprechpartners für die Geräteübernahme — informational note, always applies
        ConditionResult::True
    }

    /// [501] Hinweis: Verwendung der ID der Marktlokation
    fn evaluate_501(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Verwendung der ID der Marktlokation — informational note, always applies
        ConditionResult::True
    }

    /// [502] Hinweis: Verwendung der ID der Messlokation
    fn evaluate_502(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Verwendung der ID der Messlokation — informational note, always applies
        ConditionResult::True
    }

    /// [503] Hinweis: Es ist die MP-ID des Eigentümers (MSB) zur bilateralen Klärung anzugeben, wenn z. B. der MSBA das Gerät / die Geräte selbst gepachtet hat.
    fn evaluate_503(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Es ist die MP-ID des Eigentümers (MSB) zur bilateralen Klärung anzugeben, wenn z. B. der MSBA das Gerät / die Geräte selbst gepachtet hat.
        ConditionResult::True
    }

    /// [504] Hinweis: Wert aus BGM+311 DE1004 der REQOTE mit der die Angebotsanfrage erfolgt ist.
    fn evaluate_504(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Wert aus BGM+311 DE1004 der REQOTE mit der die Angebotsanfrage erfolgt ist.
        ConditionResult::True
    }

    /// [505] Hinweis: Wert aus BGM+Z29 DE1004 der REQOTE, mit der die Anfrage Rechnungsabwicklung erfolgt ist.
    fn evaluate_505(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Wert aus BGM+Z29 DE1004 der REQOTE, mit der die Anfrage Rechnungsabwicklung erfolgt ist.
        ConditionResult::True
    }

    /// [506] Hinweis: Wenn zu einer Position (z. B. Messwandlersatz) mehrere Gerätenummern existieren, sind die Gerätenummern in derselben Position (LIN-Segment) mittels Wiederholung der SG32 RFF+Z09 anzugeben
    fn evaluate_506(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Wenn zu einer Position mehrere Gerätenummern existieren, sind die Gerätenummern in derselben Position mittels Wiederholung der SG32 RFF+Z09 anzugeben.
        ConditionResult::True
    }

    /// [507] Hinweis: Verwendung der ID der Tranche
    fn evaluate_507(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Verwendung der ID der Tranche
        ConditionResult::True
    }

    /// [511] Hinweis: Wert aus BGM+Z74 (Bestellung eines Angebots einer Konfiguration) DE1004 der REQOTE mit der die Anfrage einer Konfiguration erfolgt ist.
    fn evaluate_511(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Wert aus BGM+Z74 DE1004 der REQOTE — informational note, always applies
        ConditionResult::True
    }

    /// [512] Hinweis: Verwendung der ID der Netzlokation
    fn evaluate_512(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Verwendung der ID der Netzlokation — informational note, always applies
        ConditionResult::True
    }

    /// [513] Hinweis: Verwendung der ID der Steuerbaren Ressource
    fn evaluate_513(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Verwendung der ID der Steuerbaren Ressource — informational note, always applies
        ConditionResult::True
    }

    /// [514] Hinweis: Angabe gemäß Preisblatt des MSB. Bis zu einmal für die Parametrierung, bis zu einmal für den Betrieb und bis zu einmal für die Transaktion, sofern im Preisblatt des MSB vorhanden.
    fn evaluate_514(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Angabe gemäß Preisblatt des MSB — informational note, always applies
        ConditionResult::True
    }

    /// [516] Hinweis: Es darf nur eine Information im DE3148 übermittelt werden
    fn evaluate_516(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Es darf nur eine Information im DE3148 übermittelt werden — informational note, always applies
        ConditionResult::True
    }

    /// [903] Format: Möglicher Wert: 1
    // REVIEW: Format condition requiring the value to equal exactly 1. Applies to a numeric field — most likely QTY[0][1] in QUOTES context. validate_numeric with == 1.0 covers this. Medium confidence because the exact segment binding isn't specified in the condition text alone. (medium confidence)
    fn evaluate_903(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("QTY", 0, 1, |val| validate_numeric(val, "==", 1.0))
    }

    /// [906] Format: max. 3 Nachkommastellen
    // REVIEW: Format condition for maximum 3 decimal places. Uses validate_max_decimal_places helper. Targeting QTY[0][1] as the most likely numeric value field in QUOTES. Medium confidence because the specific data element binding is not stated in the condition text. (medium confidence)
    fn evaluate_906(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("QTY", 0, 1, |val| validate_max_decimal_places(val, 3))
    }

    /// [908] Format: Mögliche Werte: 1 bis n
    // REVIEW: Format condition for values in range 1 to n (any positive integer). validate_numeric with >= 1.0 captures the lower bound; the upper bound n is open-ended. Targeting QTY as the most common numeric field. Medium confidence due to unspecified exact segment. (medium confidence)
    fn evaluate_908(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("QTY", 0, 1, |val| validate_numeric(val, ">=", 1.0))
    }

    /// [911] Format: Mögliche Werte: 1 bis n, je Nachricht oder Segmentgruppe bei 1 beginnend und fortlaufend aufsteigend
    fn evaluate_911(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Mögliche Werte: 1 bis n, je Nachricht oder Segmentgruppe bei 1 beginnend
        // und fortlaufend aufsteigend — informational annotation about sequential numbering,
        // always applies unconditionally
        ConditionResult::True
    }

    /// [912] Format: max. 6 Nachkommastellen
    // REVIEW: Format condition for maximum 6 decimal places. Uses validate_max_decimal_places helper with limit 6. Targeting QTY[0][1] as the primary numeric value field in QUOTES. Medium confidence because the exact data element binding is not given in the condition text. (medium confidence)
    fn evaluate_912(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("QTY", 0, 1, |val| validate_max_decimal_places(val, 6))
    }

    /// [914] Format: Möglicher Wert: &gt; 0
    // REVIEW: Format condition requiring value > 0. In QUOTES context this most likely applies to QTY element[0][1] (the quantity value). Medium confidence because the exact segment is not specified in the condition text — it depends on which data element this condition is attached to in the AHB. (medium confidence)
    fn evaluate_914(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("QTY", 0, 1, |val| validate_numeric(val, ">", 0.0))
    }

    /// [931] Format: ZZZ = +00
    // REVIEW: Format condition validating that the timezone portion (ZZZ) of a DTM value equals +00 (UTC). Uses validate_timezone_utc helper. Medium confidence because the specific DTM qualifier this applies to is not stated in the condition text — the AHB attaches this to a specific DTM element. (medium confidence)
    fn evaluate_931(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("DTM", 0, 1, validate_timezone_utc)
    }

    /// [932] Format: HHMM = 2200
    // REVIEW: Format condition requiring the HHMM portion of a DTM value to equal 2200. Uses validate_hhmm_equals helper. Medium confidence because the specific DTM qualifier (e.g., 163, 164, 137) this applies to is not stated in the condition text alone — it depends on which DTM element in the QUOTES AHB carries this constraint. (medium confidence)
    fn evaluate_932(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("DTM", 0, 1, |val| validate_hhmm_equals(val, "2200"))
    }

    /// [933] Format: HHMM = 2300
    // REVIEW: Format condition requiring the HHMM portion of a DTM value to equal 2300. Uses validate_hhmm_equals helper. Medium confidence for the same reason as 932 — specific DTM qualifier not identified from condition text alone. (medium confidence)
    fn evaluate_933(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("DTM", 0, 1, |val| validate_hhmm_equals(val, "2300"))
    }

    /// [934] Format: HHMM = 0400
    // REVIEW: Format condition requiring the HHMM portion of a DTM value to equal 0400. Uses validate_hhmm_equals helper. Medium confidence for the same reason as 932/933 — specific DTM qualifier not identified from condition text alone. In QUOTES context, 0400 likely represents a gas day start time. (medium confidence)
    fn evaluate_934(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("DTM", 0, 1, |val| validate_hhmm_equals(val, "0400"))
    }

    /// [935] Format: HHMM = 0500
    // REVIEW: Format condition checking HHMM = 0500 on a DTM segment. Without a specific qualifier reference provided for this QUOTES condition, falls back to the first DTM segment. validate_hhmm_equals extracts the HHMM portion of the datetime value and compares it to '0500'. (medium confidence)
    fn evaluate_935(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("DTM", 0, 1, |val| validate_hhmm_equals(val, "0500"))
    }

    /// [939] Format: Die Zeichenkette muss die Zeichen @ und . enthalten
    // REVIEW: Checks COM segments for email-format values (must contain '@' and '.'). COM is the standard EDIFACT segment for communication channels where email addresses appear (qualifier EM). Scans all COM values since context doesn't specify which occurrence to validate. (medium confidence)
    fn evaluate_939(&self, ctx: &EvaluationContext) -> ConditionResult {
        for seg in ctx.find_segments("COM") {
            if let Some(elem) = seg.elements.first() {
                if let Some(value) = elem.first() {
                    if value.contains('@') && value.contains('.') {
                        return ConditionResult::True;
                    }
                }
            }
        }
        ConditionResult::False
    }

    /// [940] Format: Die Zeichenkette muss mit dem Zeichen + beginnen und danach dürfen nur noch Ziffern folgen
    // REVIEW: Checks COM segments for international phone number format (starts with '+' followed only by digits). COM is the standard segment for telephone contacts. Scans all COM values since context doesn't specify which occurrence to validate. (medium confidence)
    fn evaluate_940(&self, ctx: &EvaluationContext) -> ConditionResult {
        for seg in ctx.find_segments("COM") {
            if let Some(elem) = seg.elements.first() {
                if let Some(value) = elem.first() {
                    if value.starts_with('+') && value.chars().skip(1).all(|c| c.is_ascii_digit()) {
                        return ConditionResult::True;
                    }
                }
            }
        }
        ConditionResult::False
    }

    /// [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])
        })
    }

    /// [950] Format: Marktlokations-ID
    fn evaluate_950(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check_qualified("LOC", 0, "Z16", 1, 0, validate_malo_id)
    }

    /// [951] Format: Zählpunktbezeichnung
    fn evaluate_951(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check_qualified("LOC", 0, "Z17", 1, 0, validate_zahlpunkt)
    }

    /// [960] Format: Netzlokations-ID
    // REVIEW: Netzlokations-ID is associated with LOC+Z18 (Netzlokation qualifier). The Netzlokations-ID shares the same 11-digit structure with Luhn check as the Marktlokations-ID. No dedicated validate_netzlokation_id helper exists, so validate_malo_id is used as the structurally equivalent validator. (medium confidence)
    fn evaluate_960(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check_qualified("LOC", 0, "Z18", 1, 0, validate_malo_id)
    }

    /// [962] Format: max. 6 Vorkommastellen
    // REVIEW: Uses validate_max_integer_digits(value, 6) on the PRI price amount value. Standard EDIFACT PRI C509 places DE5118 (price amount) at elements[0][1]. PRI segment structure is not explicitly listed in the provided MIG reference so medium confidence on the element index. (medium confidence)
    fn evaluate_962(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("PRI", 0, 1, |val| validate_max_integer_digits(val, 6))
    }

    /// [2042] Innerhalb dieser LIN-Position muss das PIA+Z02 (Artikel-ID) mindestens ein Mal angegeben werden und kann bis zu drei Mal angegeben werden.
    // REVIEW: Counts PIA segments where elements[0][0] == 'Z02' (DE4347 Artikel-ID qualifier per segment structure reference) and verifies the count is between 1 and 3 inclusive. Medium confidence because the condition is scoped to 'within this LIN position' (SG27) but we count message-wide; in REQOTE the PIA+Z02 segments appear within SG27 position groups. (medium confidence)
    fn evaluate_2042(&self, ctx: &EvaluationContext) -> ConditionResult {
        let count = ctx
            .find_segments("PIA")
            .iter()
            .filter(|s| {
                s.elements
                    .first()
                    .and_then(|e| e.first())
                    .is_some_and(|v| v == "Z02")
            })
            .count();
        ConditionResult::from(count >= 1 && count <= 3)
    }

    /// [2060] Pro Nachricht ist die SG27 LIN+Z64 (Erforderliches Produkt Schaltzeitdefinitionen) maximal einmal anzugeben
    fn evaluate_2060(&self, ctx: &EvaluationContext) -> ConditionResult {
        let count = ctx
            .find_segments("LIN")
            .iter()
            .filter(|s| {
                s.elements
                    .get(1)
                    .and_then(|e| e.first())
                    .is_some_and(|v| v == "Z64")
            })
            .count();
        ConditionResult::from(count <= 1)
    }

    /// [2061] Pro Nachricht ist die SG27 LIN++Z65 (Erforderliches Produkt Leistungskurvendefinitionen) maximal einmal anzugeben
    fn evaluate_2061(&self, ctx: &EvaluationContext) -> ConditionResult {
        let count = ctx
            .find_segments("LIN")
            .iter()
            .filter(|s| {
                s.elements
                    .get(1)
                    .and_then(|e| e.first())
                    .is_some_and(|v| v == "Z65")
            })
            .count();
        ConditionResult::from(count <= 1)
    }

    /// [2062] Pro Nachricht ist die SG27 LIN++Z66 (Erforderliches Produkt Ad-hoc-Steuerkanal) maximal einmal anzugeben
    fn evaluate_2062(&self, ctx: &EvaluationContext) -> ConditionResult {
        let count = ctx.find_segments_with_qualifier("LIN", 1, "Z66").len();
        ConditionResult::from(count <= 1)
    }

    /// [2063] Pro Nachricht ist die SG27 LIN++Z67 (Erforderliches Messprodukt für Werte nach Typ 2 aus Backend) maximal einmal anzugeben
    fn evaluate_2063(&self, ctx: &EvaluationContext) -> ConditionResult {
        let count = ctx.find_segments_with_qualifier("LIN", 1, "Z67").len();
        ConditionResult::from(count <= 1)
    }

    /// [2064] Pro Nachricht ist die SG27 LIN++Z68 (Erforderliches Produkt Konfigurationserlaubnis für Werte nach Typ 2 aus SMGW) maximal einmal anzugeben
    fn evaluate_2064(&self, ctx: &EvaluationContext) -> ConditionResult {
        let count = ctx.find_segments_with_qualifier("LIN", 1, "Z68").len();
        ConditionResult::from(count <= 1)
    }

    /// [2068] Pro SG27 LIN ist die SG31 PRI genau einmal anzugeben.
    // REVIEW: Checks that every SG27 instance has exactly one SG31 child group (PRI). Uses group navigator to count SG31 children per SG27 instance. Returns True only when all SG27s have exactly one SG31. (medium confidence)
    fn evaluate_2068(&self, ctx: &EvaluationContext) -> ConditionResult {
        let nav = match ctx.navigator() {
            Some(n) => n,
            None => return ConditionResult::Unknown,
        };
        let sg27_count = nav.group_instance_count(&["SG27"]);
        if sg27_count == 0 {
            return ConditionResult::Unknown;
        }
        for i in 0..sg27_count {
            let sg31_count = nav.child_group_instance_count(&["SG27"], i, "SG31");
            if sg31_count != 1 {
                return ConditionResult::False;
            }
        }
        ConditionResult::True
    }

    /// [2069] Pro SG27 LIN ist die SG31 PRI genau einmal anzugeben. Dabei muss in der SG31 PRI im DE5284 eine Mengenangabe mit dem Code H87 (Stück) im DE6411 angegeben sein.
    // REVIEW: Checks that count_in_group for PRI in SG31 equals exactly 1 and that the PRI contains H87 in DE6411 (C509 index 4 = elements[0][1] is price amount; index 4 is unit of measure per standard EDIFACT C509 layout: DE5125, DE5118, DE5375, DE5419, DE6411). PRI structure not in the provided MIG reference so medium confidence on the DE6411 index. (medium confidence)
    fn evaluate_2069(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Pro SG27 LIN: SG31 PRI must appear exactly once with H87 (Stück) in DE6411
        let pri_count = ctx.count_in_group("PRI", &["SG27", "SG31"]);
        if pri_count != 1 {
            return ConditionResult::False;
        }
        // DE6411 is the 5th component of C509 = elements[0][4]
        let segs = ctx.find_segments("PRI");
        match segs.first() {
            Some(pri) => {
                let unit = pri
                    .elements
                    .first()
                    .and_then(|e| e.get(4))
                    .map(|s| s.as_str());
                ConditionResult::from(unit == Some("H87"))
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [2070] Pro SG27 LIN ist die SG31 PRI zweimal anzugeben. Dabei muss genau eine SG31 PRI mit Preis- und Mengenangabe und dem Code H87 (Stück) im DE6411 und genau eine SG31 PRI mit Preis- und Mengenangabe u...
    // REVIEW: Checks that SG31 PRI appears exactly twice and that among those two entries one has H87 and one has DAY in DE6411 (C509 index 4 = elements[0][4]). Same caveat as 2069 — PRI structure not in the provided MIG reference so medium confidence on the component index for DE6411. (medium confidence)
    fn evaluate_2070(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Pro SG27 LIN: SG31 PRI must appear exactly twice — one with H87 (Stück), one with DAY (Tag) in DE6411
        let pri_count = ctx.count_in_group("PRI", &["SG27", "SG31"]);
        if pri_count != 2 {
            return ConditionResult::False;
        }
        // DE6411 is elements[0][4] in standard EDIFACT C509
        let segs = ctx.find_segments("PRI");
        let has_h87 = segs.iter().any(|pri| {
            pri.elements
                .first()
                .and_then(|e| e.get(4))
                .is_some_and(|v| v == "H87")
        });
        let has_day = segs.iter().any(|pri| {
            pri.elements
                .first()
                .and_then(|e| e.get(4))
                .is_some_and(|v| v == "DAY")
        });
        ConditionResult::from(has_h87 && has_day)
    }

    /// [2071] Diese SG31 PRI (Preisangabe zur Position) ist bis zu dreimal anzugeben. Es ist so oft anzugeben, wie innerhalb derselben SG27 LIN (Erforderliches Messprodukt für Werte nach Typ2 aus Backend) das P...
    fn evaluate_2071(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Cardinality rule — SG31 PRI (Preisangabe) is given up to three times,
        // as often as PIA+Z02 (Artikel-ID) appears in the same SG27 LIN (Erforderliches Messprodukt
        // für Werte nach Typ2 aus Backend). Informational cardinality annotation, always applies.
        ConditionResult::True
    }

    /// [2072] Diese SG31 PRI (Preisangabe zur Position) ist bis zu dreimal anzugeben. Es ist so oft anzugeben, wie innerhalb derselben SG27 LIN (Erforderliches Produkt Konfigurationserlaubnis für Werte nach Typ...
    fn evaluate_2072(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Cardinality rule — SG31 PRI (Preisangabe) is given up to three times,
        // as often as PIA+Z02 (Artikel-ID) appears in the same SG27 LIN (Erforderliches Produkt
        // Konfigurationserlaubnis für Werte nach Typ 2 aus SMGW). Informational cardinality annotation, always applies.
        ConditionResult::True
    }

    /// [2073] Das PIA (OBIS-Kennzahl für Werte nach Typ 2 Backend) ist mindestens einmal anzugeben. Es kann in Abhängigkeit zu den anderen PIA Segmenten innerhalb derselben SG27 LIN (Erforderliches Messprodukt...
    fn evaluate_2073(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Cardinality rule — PIA (OBIS-Kennzahl für Werte nach Typ 2 Backend) must appear
        // at least once. It can appear up to 23 times if the other PIA segments in the same SG27 LIN
        // appear at most once each. The maximum total number of PIA segments per SG27 LIN is 25.
        // Informational cardinality annotation, always applies.
        ConditionResult::True
    }
}