automapper-validation 0.1.55

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
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
// <auto-generated>
// Generated by automapper-generator generate-conditions
// AHB: xml-migs-and-ahbs/FV2504/INVOIC_AHB_2_5d_Fehlerkorrektur_20250623.xml
// Generated: 2026-03-12T10:18:43Z
// </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};

/// Resolve the (DTM+137 date, resolved current date) pair used by Werktag
/// conditions [24]/[25]. Returns `None` if either side is missing or
/// unparseable — callers should treat that as `Unknown`.
fn dtm137_and_current_dates(
    ctx: &EvaluationContext,
) -> Option<(chrono::NaiveDate, chrono::NaiveDate)> {
    let current = parse_ccyymmdd_prefix(ctx.resolved_value?)?;
    let dtm137 = ctx
        .find_segments_with_qualifier("DTM", 0, "137")
        .into_iter()
        .find_map(|s| {
            s.elements
                .first()
                .and_then(|e| e.get(1))
                .filter(|v| !v.is_empty())
                .and_then(|v| parse_ccyymmdd_prefix(v))
        })?;
    Some((dtm137, current))
}

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

impl Default for InvoicConditionEvaluatorFV2504 {
    fn default() -> Self {
        let mut external_conditions = std::collections::HashSet::new();
        external_conditions.insert(1);
        external_conditions.insert(2);
        external_conditions.insert(3);
        external_conditions.insert(7);
        external_conditions.insert(8);
        external_conditions.insert(11);
        external_conditions.insert(13);
        external_conditions.insert(15);
        external_conditions.insert(16);
        external_conditions.insert(28);
        external_conditions.insert(30);
        external_conditions.insert(31);
        external_conditions.insert(34);
        external_conditions.insert(37);
        external_conditions.insert(40);
        external_conditions.insert(45);
        external_conditions.insert(67);
        external_conditions.insert(68);
        external_conditions.insert(69);
        external_conditions.insert(72);
        external_conditions.insert(76);
        external_conditions.insert(492);
        external_conditions.insert(493);
        Self {
            external_conditions,
        }
    }
}

impl ConditionEvaluator for InvoicConditionEvaluatorFV2504 {
    fn message_type(&self) -> &str {
        "INVOIC"
    }

    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),
            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),
            14 => self.evaluate_14(ctx),
            15 => self.evaluate_15(ctx),
            16 => self.evaluate_16(ctx),
            17 => self.evaluate_17(ctx),
            18 => self.evaluate_18(ctx),
            19 => self.evaluate_19(ctx),
            20 => self.evaluate_20(ctx),
            21 => self.evaluate_21(ctx),
            22 => self.evaluate_22(ctx),
            23 => self.evaluate_23(ctx),
            24 => self.evaluate_24(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),
            32 => self.evaluate_32(ctx),
            34 => self.evaluate_34(ctx),
            36 => self.evaluate_36(ctx),
            37 => self.evaluate_37(ctx),
            40 => self.evaluate_40(ctx),
            41 => self.evaluate_41(ctx),
            42 => self.evaluate_42(ctx),
            44 => self.evaluate_44(ctx),
            45 => self.evaluate_45(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),
            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),
            64 => self.evaluate_64(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),
            76 => self.evaluate_76(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),
            84 => self.evaluate_84(ctx),
            85 => self.evaluate_85(ctx),
            86 => self.evaluate_86(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),
            501 => self.evaluate_501(ctx),
            502 => self.evaluate_502(ctx),
            503 => self.evaluate_503(ctx),
            504 => self.evaluate_504(ctx),
            507 => self.evaluate_507(ctx),
            508 => self.evaluate_508(ctx),
            509 => self.evaluate_509(ctx),
            510 => self.evaluate_510(ctx),
            512 => self.evaluate_512(ctx),
            513 => self.evaluate_513(ctx),
            514 => self.evaluate_514(ctx),
            515 => self.evaluate_515(ctx),
            516 => self.evaluate_516(ctx),
            517 => self.evaluate_517(ctx),
            518 => self.evaluate_518(ctx),
            519 => self.evaluate_519(ctx),
            520 => self.evaluate_520(ctx),
            521 => self.evaluate_521(ctx),
            522 => self.evaluate_522(ctx),
            523 => self.evaluate_523(ctx),
            524 => self.evaluate_524(ctx),
            525 => self.evaluate_525(ctx),
            526 => self.evaluate_526(ctx),
            902 => self.evaluate_902(ctx),
            906 => self.evaluate_906(ctx),
            908 => self.evaluate_908(ctx),
            910 => self.evaluate_910(ctx),
            911 => self.evaluate_911(ctx),
            912 => self.evaluate_912(ctx),
            914 => self.evaluate_914(ctx),
            927 => self.evaluate_927(ctx),
            930 => self.evaluate_930(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),
            937 => self.evaluate_937(ctx),
            939 => self.evaluate_939(ctx),
            940 => self.evaluate_940(ctx),
            946 => self.evaluate_946(ctx),
            950 => self.evaluate_950(ctx),
            951 => self.evaluate_951(ctx),
            960 => self.evaluate_960(ctx),
            961 => self.evaluate_961(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
                | 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
                | 34
                | 36
                | 37
                | 40
                | 41
                | 42
                | 44
                | 45
                | 47
                | 48
                | 49
                | 50
                | 51
                | 53
                | 54
                | 55
                | 56
                | 57
                | 58
                | 59
                | 60
                | 61
                | 64
                | 65
                | 66
                | 67
                | 68
                | 69
                | 70
                | 71
                | 72
                | 73
                | 74
                | 75
                | 76
                | 77
                | 78
                | 79
                | 80
                | 81
                | 82
                | 84
                | 85
                | 86
                | 88
                | 490
                | 491
                | 492
                | 493
                | 501
                | 502
                | 503
                | 504
                | 507
                | 508
                | 509
                | 510
                | 512
                | 513
                | 514
                | 515
                | 516
                | 517
                | 518
                | 519
                | 520
                | 521
                | 522
                | 523
                | 524
                | 525
                | 526
                | 902
                | 906
                | 908
                | 910
                | 911
                | 912
                | 914
                | 927
                | 930
                | 931
                | 932
                | 933
                | 934
                | 935
                | 937
                | 939
                | 940
                | 946
                | 950
                | 951
                | 960
                | 961
        )
    }
}

impl InvoicConditionEvaluatorFV2504 {
    /// [1] Wenn in zu stornierender Rechnung gefüllt
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_1(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external
            .evaluate("invoice_being_cancelled_field_filled")
    }

    /// [2] Wenn es sich um eine Nutzungsüberlassung (Pacht) eines Gerätes handelt
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_2(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("is_device_lease")
    }

    /// [3] Wenn es sich um einen Kauf eines Gerätes handelt
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_3(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("is_device_purchase")
    }

    /// [7] Sofern keine Großkundenpostleitzahl verwendet wird
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_7(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("no_large_customer_postal_code")
    }

    /// [8] Bei zeitabhängigen Preisen
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_8(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("is_time_dependent_pricing")
    }

    /// [11] Wenn Abschlag anfällt
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Whether a deposit/advance payment (Abschlag) applies is business context that cannot be determined from the EDIFACT message structure alone — it depends on the contract type and billing arrangement. (medium confidence)
    fn evaluate_11(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("advance_payment_applies")
    }

    /// [13] Wenn vorausbezahlter Betrag vorliegt
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Whether a prepaid amount (vorausbezahlter Betrag) is present is billing business context that cannot be derived solely from the EDIFACT segments in the message. (medium confidence)
    fn evaluate_13(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("prepaid_amount_present")
    }

    /// [15] Wenn eine Bilanzierung erfolgt ist
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Whether a balancing (Bilanzierung) has occurred is operational/business context external to the EDIFACT message itself. (medium confidence)
    fn evaluate_15(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("balancing_performed")
    }

    /// [16] Wenn eine Netznutzung erfolgt ist
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Whether network usage (Netznutzung) has occurred is business context that cannot be determined solely from the EDIFACT message content. (medium confidence)
    fn evaluate_16(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("network_usage_performed")
    }

    /// [24] Wert muss mindestens 10 WT nach Wert aus DTM+137 DE2380 liegen
    // REVIEW: Compares resolved_value (current DTM's DE2380, a due date in format 303 CCYYMMDDHHMM) against DTM+137 DE2380 (Nachrichtendatum) found message-wide. True when werktage_between(dtm137, resolved) >= 10. Uses BDEW federal-holiday set + Easter computation.
    fn evaluate_24(&self, ctx: &EvaluationContext) -> ConditionResult {
        let (dtm137, current) = match dtm137_and_current_dates(ctx) {
            Some(pair) => pair,
            None => return ConditionResult::Unknown,
        };
        ConditionResult::from(werktage_between(dtm137, current) >= 10)
    }

    /// [25] Wert darf maximal 10 WT nach Wert aus DTM+137 DE2380 liegen
    // REVIEW: Same inputs as [24]. True when werktage_between(dtm137, resolved) <= 10.
    fn evaluate_25(&self, ctx: &EvaluationContext) -> ConditionResult {
        let (dtm137, current) = match dtm137_and_current_dates(ctx) {
            Some(pair) => pair,
            None => return ConditionResult::Unknown,
        };
        ConditionResult::from(werktage_between(dtm137, current) <= 10)
    }

    /// [34] Wenn in Ursprungsrechnung vorhanden
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: "Wenn in Ursprungsrechnung vorhanden" means the condition is met when the corresponding value was present in the referenced original invoice. That original document is not available inside the current EDIFACT message, so this is an external business-context check. (medium confidence)
    fn evaluate_34(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("in_original_invoice")
    }

    /// [37] Wenn Lieferschein zuvor ausgetauscht wurde
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: "Wenn Lieferschein zuvor ausgetauscht wurde" depends on whether a delivery note (Lieferschein) was exchanged in a prior business transaction. This cannot be determined from the current EDIFACT message alone; it requires external business context. (medium confidence)
    fn evaluate_37(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("delivery_note_previously_exchanged")
    }

    /// [40] Es sind nur die Artikelnummern erlaubt, die in der Codeliste der Artikelnummern und Artikel-ID mit dem entsprechenden Prüfidentifikator versehen sind oder Artikel-ID aus der Codeliste der Artikeln...
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Condition requires validating that the article number/ID appears in the external "Codeliste der Artikelnummern und Artikel-ID" for the given Prüfidentifikator. Code-list membership cannot be verified from the EDIFACT message structure alone; it is an external reference-data check. (medium confidence)
    fn evaluate_40(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("artikel_id_in_codeliste")
    }

    /// [45] Nur MP-ID aus Sparte Strom
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: "Nur MP-ID aus Sparte Strom" means only market-participant IDs that belong to the electricity sector are allowed. Determining which IDs are registered for Sparte Strom requires an external code list or market master data lookup and cannot be inferred from the EDIFACT message content. (medium confidence)
    fn evaluate_45(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("mp_id_sparte_strom")
    }

    /// [67] Es sind nur die Artikelnummern erlaubt, die im Kapitel 2 „Codeliste der Artikelnummer“ in der Codeliste der Artikelnummern und Artikel-ID ein „X“ für den entsprechenden Prüfidentifikator ...
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_67(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("artikelnummer_allowed_for_pid")
    }

    /// [68] Es sind nur die Artikel-ID erlaubt, die im Kapitel 3 „Codeliste der Gruppenartikel-ID und Artikel-ID“  in der Codeliste der Artikelnummern und Artikel-ID ein „X“ in der Spalte „INVOIC Cod...
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_68(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("artikel_id_invoic_allowed")
    }

    /// [69] Es sind nur die Artikel-ID erlaubt, die im Kapitel 3 „Codeliste der Gruppenartikel-ID und Artikel-ID“  in der Codeliste der Artikelnummern und Artikel-ID ein „SOR“ in der Spalte „INVOIC C...
    /// EXTERNAL: Requires context from outside the message.
    fn evaluate_69(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("artikel_id_invoic_sor_allowed")
    }

    /// [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,
        }
    }

    /// [4] Wenn Steuerschuldnerschaft des Leistungsempfängers vorliegt
    // REVIEW: "Wenn Steuerschuldnerschaft des Leistungsempfängers vorliegt" is the reverse charge mechanism. In UN/EDIFACT INVOIC, TAX category code "AE" (VAT Reverse Charge) signals this. The TAX segment composite C241 component 3 holds the tax category code. Medium confidence because element indices are derived from standard UN/EDIFACT TAX structure without a specific MIG segment structure reference to confirm the exact index for this INVOIC variant. (medium confidence)
    fn evaluate_4(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Steuerschuldnerschaft des Leistungsempfängers = reverse charge (VAT category AE)
        // In EDIFACT INVOIC the TAX segment carries duty/tax type category code.
        // UN/EDIFACT code "AE" = VAT Reverse Charge (Steuerschuldnerschaft des Leistungsempfängers).
        // TAX+7+VAT+++:::AE — elements[4][3] holds the tax category code.
        let tax_segs = ctx.find_segments("TAX");
        for seg in &tax_segs {
            // elements[4] is the duty/tax account detail composite (C241 in UN/EDIFACT TAX)
            // component 3 (index 3) is the duty/tax rate category code
            if let Some(code) = seg.elements.get(4).and_then(|e| e.get(3)) {
                if code == "AE" {
                    return ConditionResult::True;
                }
            }
        }
        ConditionResult::False
    }

    /// [5] Wenn NAD+MR DE3207 &lt;&gt; „DE“
    fn evaluate_5(&self, ctx: &EvaluationContext) -> ConditionResult {
        let nads = ctx.find_segments_with_qualifier("NAD", 0, "MR");
        match nads.first() {
            Some(nad) => {
                match nad
                    .elements
                    .get(8)
                    .and_then(|e| e.first())
                    .map(|s| s.as_str())
                {
                    Some(country) => ConditionResult::from(country != "DE"),
                    None => ConditionResult::False, // segment absent → condition not applicable
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [6] Wenn NAD+MR DE3207 = „DE“
    fn evaluate_6(&self, ctx: &EvaluationContext) -> ConditionResult {
        let nads = ctx.find_segments_with_qualifier("NAD", 0, "MR");
        match nads.first() {
            Some(nad) => {
                match nad
                    .elements
                    .get(8)
                    .and_then(|e| e.first())
                    .map(|s| s.as_str())
                {
                    Some(country) => ConditionResult::from(country == "DE"),
                    None => ConditionResult::False, // segment absent → condition not applicable
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [9] Wenn SG26 DTM+203 nicht vorhanden
    // REVIEW: Checks whether any SG26 instance lacks DTM+203 (Ausführungsdatum). Uses group navigator when available, falling back to message-wide absence check. DTM qualifier at elements[0][0]. (medium confidence)
    fn evaluate_9(&self, ctx: &EvaluationContext) -> ConditionResult {
        // DTM+203 (Ausführungsdatum) absence in the current SG26 context.
        // Falls back to message-wide check when no group navigator available.
        let nav = match ctx.navigator() {
            Some(n) => n,
            None => return ctx.lacks_qualifier("DTM", 0, "203"),
        };
        let sg26_count = nav.group_instance_count(&["SG26"]);
        for i in 0..sg26_count {
            let dtms = nav.find_segments_in_group("DTM", &["SG26"], i);
            let has_203 = dtms.iter().any(|s| {
                s.elements
                    .first()
                    .and_then(|e| e.first())
                    .is_some_and(|v| v == "203")
            });
            if !has_203 {
                return ConditionResult::True;
            }
        }
        if sg26_count == 0 {
            return ctx.lacks_qualifier("DTM", 0, "203");
        }
        ConditionResult::False
    }

    /// [10] Wenn SG26 DTM+155/156 nicht vorhanden
    // REVIEW: Both DTM+155 (Abrechnungszeitraum Beginn) and DTM+156 (Ende) must be absent in the SG26. Uses group navigator; both must be absent simultaneously for the condition to be True. (medium confidence)
    fn evaluate_10(&self, ctx: &EvaluationContext) -> ConditionResult {
        // DTM+155 (Abrechnungszeitraum Beginn) and DTM+156 (Ende) both absent in SG26.
        // Falls back to message-wide check when no group navigator available.
        let nav = match ctx.navigator() {
            Some(n) => n,
            None => {
                let no_155 = ctx.lacks_qualifier("DTM", 0, "155");
                let no_156 = ctx.lacks_qualifier("DTM", 0, "156");
                return match (no_155, no_156) {
                    (ConditionResult::True, ConditionResult::True) => ConditionResult::True,
                    (ConditionResult::False, _) | (_, ConditionResult::False) => {
                        ConditionResult::False
                    }
                    _ => ConditionResult::Unknown,
                };
            }
        };
        let sg26_count = nav.group_instance_count(&["SG26"]);
        for i in 0..sg26_count {
            let dtms = nav.find_segments_in_group("DTM", &["SG26"], i);
            let has_155 = dtms.iter().any(|s| {
                s.elements
                    .first()
                    .and_then(|e| e.first())
                    .is_some_and(|v| v == "155")
            });
            let has_156 = dtms.iter().any(|s| {
                s.elements
                    .first()
                    .and_then(|e| e.first())
                    .is_some_and(|v| v == "156")
            });
            if !has_155 && !has_156 {
                return ConditionResult::True;
            }
        }
        if sg26_count == 0 {
            let no_155 = ctx.lacks_qualifier("DTM", 0, "155");
            let no_156 = ctx.lacks_qualifier("DTM", 0, "156");
            return match (no_155, no_156) {
                (ConditionResult::True, ConditionResult::True) => ConditionResult::True,
                (ConditionResult::False, _) | (_, ConditionResult::False) => ConditionResult::False,
                _ => ConditionResult::Unknown,
            };
        }
        ConditionResult::False
    }

    /// [12] Wenn SG26 QTY+136 vorhanden
    fn evaluate_12(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("QTY", 0, "136")
    }

    /// [14] Wenn in selben SG26 LIN DE7140 = "9990001000748" (Mehrmenge)
    fn evaluate_14(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Check if any SG26 LIN has DE7140 (Produkt-/Leistungsnummer) = "9990001000748" (Mehrmenge).
        // LIN is the entry segment of SG26; elements[2][0] = DE7140.
        let lins = ctx.find_segments("LIN");
        ConditionResult::from(lins.iter().any(|s| {
            s.elements
                .get(2)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "9990001000748")
        }))
    }

    /// [17] Wenn DTM+Z11 vorhanden
    fn evaluate_17(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("DTM", 0, "Z11")
    }

    /// [18] Wenn IMD++WIM nicht vorhanden
    fn evaluate_18(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.lacks_qualifier("IMD", 1, "WIM")
    }

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

    /// [20] Wenn fälliger Betrag (SG50 MOA+9) ≥ 0
    // REVIEW: MOA+9 is fälliger Betrag (due amount): elements[0][0]='9', elements[0][1]=amount. Parses the numeric value and checks >= 0. (medium confidence)
    fn evaluate_20(&self, ctx: &EvaluationContext) -> ConditionResult {
        let moas = ctx.find_segments_with_qualifier("MOA", 0, "9");
        match moas.first() {
            Some(moa) => match moa.elements.first().and_then(|e| e.get(1)) {
                Some(val) => match val.parse::<f64>() {
                    Ok(n) => ConditionResult::from(n >= 0.0),
                    Err(_) => ConditionResult::Unknown,
                },
                None => ConditionResult::False, // segment absent → condition not applicable
            },
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [21] Wenn fälliger Betrag (SG50 MOA+9) &lt; 0
    // REVIEW: MOA+9 is fälliger Betrag. Parses numeric value and checks < 0. Inverse of condition 20. (medium confidence)
    fn evaluate_21(&self, ctx: &EvaluationContext) -> ConditionResult {
        let moas = ctx.find_segments_with_qualifier("MOA", 0, "9");
        match moas.first() {
            Some(moa) => match moa.elements.first().and_then(|e| e.get(1)) {
                Some(val) => match val.parse::<f64>() {
                    Ok(n) => ConditionResult::from(n < 0.0),
                    Err(_) => ConditionResult::Unknown,
                },
                None => ConditionResult::False, // segment absent → condition not applicable
            },
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [22] Wenn vorhanden
    fn evaluate_22(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Wenn vorhanden — self-referential presence condition, always True when evaluated
        ConditionResult::True
    }

    /// [23] Wenn im selben NAD DE3124 nicht vorhanden
    // REVIEW: DE3124 resides in C058 at elements[2][0] for all NAD variants. 'Im selben NAD' means within the same NAD instance; evaluated message-wide as: any NAD where this component is absent or empty. (medium confidence)
    fn evaluate_23(&self, ctx: &EvaluationContext) -> ConditionResult {
        let nads = ctx.find_segments("NAD");
        if nads.is_empty() {
            return ConditionResult::Unknown;
        }
        // True if any NAD has DE3124 (elements[2][0] from C058) absent or empty
        ConditionResult::from(nads.iter().any(|nad| {
            nad.elements
                .get(2)
                .and_then(|e| e.first())
                .map_or(true, |v| v.is_empty())
        }))
    }

    /// [26] Wenn SG39 ALC+A+:Z04 vorhanden
    fn evaluate_26(&self, ctx: &EvaluationContext) -> ConditionResult {
        let alcs = ctx.find_segments_with_qualifier("ALC", 0, "A");
        ConditionResult::from(alcs.iter().any(|alc| {
            alc.elements
                .get(1)
                .and_then(|e| e.get(1))
                .map_or(false, |v| v == "Z04")
        }))
    }

    /// [27] Wenn SG39 ALC+C vorhanden
    fn evaluate_27(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualifier("ALC", 0, "C")
    }

    /// [28] Wenn Zuschlag anfällt
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: 'Wenn Zuschlag anfällt' (if a surcharge applies) is a business-context determination that cannot be derived from EDIFACT segment content alone. It depends on contract terms or tariff configuration held outside the message. (medium confidence)
    fn evaluate_28(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("surcharge_applies")
    }

    /// [29] [Wenn DTM+155 (Abrechnungszeitraum Beginn) nicht größer 31.12.2015
    // REVIEW: DTM+155 is Abrechnungszeitraum Beginn with format 303 (starts YYYYMMDD). 'nicht größer 31.12.2015' means <= 31.12.2015. Lexicographic comparison of 8-char ISO prefix is correct for this date format. (medium confidence)
    fn evaluate_29(&self, ctx: &EvaluationContext) -> ConditionResult {
        let dtms = ctx.find_segments_with_qualifier("DTM", 0, "155");
        match dtms.first() {
            Some(dtm) => {
                match dtm.elements.first().and_then(|e| e.get(1)) {
                    Some(val) if val.len() >= 8 => {
                        // Format 303: CCYYMMDDHHMMSSZZZ — compare YYYYMMDD prefix
                        let date_prefix = &val[..8];
                        ConditionResult::from(date_prefix <= "20151231")
                    }
                    _ => ConditionResult::Unknown,
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [30] Wenn MP-ID in NAD+MR nicht in der Rolle MGV oder KN
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: 'Wenn MP-ID in NAD+MR nicht in der Rolle MGV oder KN' requires knowledge of which market-participant IDs correspond to the MGV (Messstellenbetreiber Gasvertrieb) or KN (Kunde/Netz) roles. Role assignment is maintained in an external registry and cannot be determined from the NAD segment alone. (medium confidence)
    fn evaluate_30(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("recipient_not_mgv_or_kn")
    }

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

    /// [32] Wenn SG39 ALC+A+:Z01 (Gemeinderabatt) vorhanden
    fn evaluate_32(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.has_qualified_value("ALC", 0, "A", 1, 1, &["Z01"])
    }

    /// [36] Wenn DTM+156 (Abrechnungszeitraum Ende) ≥ 01.12.2019
    // REVIEW: DTM+156 (Abrechnungszeitraum Ende) uses format 303 (CCYYMMDDHHMM), so lexicographic string comparison is correct. German date 01.12.2019 = December 1, 2019 = "201912010000". (medium confidence)
    fn evaluate_36(&self, ctx: &EvaluationContext) -> ConditionResult {
        let dtm_segs = ctx.find_segments_with_qualifier("DTM", 0, "156");
        match dtm_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() => {
                        // Format 303 = CCYYMMDDHHMM; lexicographic comparison works for zero-padded timestamps.
                        // 01.12.2019 (DD.MM.YYYY) = December 1, 2019 = "201912010000"
                        ConditionResult::from(value >= "201912010000")
                    }
                    _ => ConditionResult::Unknown,
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [41] Wenn IMD++SOR vorhanden
    fn evaluate_41(&self, ctx: &EvaluationContext) -> ConditionResult {
        let imds = ctx.find_segments("IMD");
        ConditionResult::from(imds.iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "SOR")
        }))
    }

    /// [42] Wenn DTM+155 (Abrechnungszeitraum Beginn) ≥ 1.1.2023 0:00 gesetzlicher deutscher Zeit
    // REVIEW: DTM+155 (Abrechnungszeitraum Beginn) uses format 303 (CCYYMMDDHHMM). January 1, 2023 at 00:00 = "202301010000". Lexicographic comparison is correct for zero-padded CCYYMMDDHHMM. (medium confidence)
    fn evaluate_42(&self, ctx: &EvaluationContext) -> ConditionResult {
        let dtm_segs = ctx.find_segments_with_qualifier("DTM", 0, "155");
        match dtm_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() => {
                        // Format 303 = CCYYMMDDHHMM; 1.1.2023 0:00 gesetzlicher Zeit = "202301010000"
                        ConditionResult::from(value >= "202301010000")
                    }
                    _ => ConditionResult::Unknown,
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [44] Wenn IMD++ABS nicht vorhanden
    fn evaluate_44(&self, ctx: &EvaluationContext) -> ConditionResult {
        let imds = ctx.find_segments("IMD");
        ConditionResult::from(!imds.iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "ABS")
        }))
    }

    /// [47] Wenn IMD++Z43 vorhanden
    fn evaluate_47(&self, ctx: &EvaluationContext) -> ConditionResult {
        let imds = ctx.find_segments("IMD");
        ConditionResult::from(imds.iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z43")
        }))
    }

    /// [48] Wenn IMD++Z44 vorhanden
    fn evaluate_48(&self, ctx: &EvaluationContext) -> ConditionResult {
        let imds = ctx.find_segments("IMD");
        ConditionResult::from(imds.iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z44")
        }))
    }

    /// [49] Wenn IMD++Z43 und IMD+Z44 nicht vorhanden
    fn evaluate_49(&self, ctx: &EvaluationContext) -> ConditionResult {
        let imds = ctx.find_segments("IMD");
        let has_z43 = imds.iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z43")
        });
        let has_z44 = imds.iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z44")
        });
        ConditionResult::from(!has_z43 && !has_z44)
    }

    /// [50] Wenn IMD++SOR nicht vorhanden
    fn evaluate_50(&self, ctx: &EvaluationContext) -> ConditionResult {
        let imds = ctx.find_segments("IMD");
        ConditionResult::from(!imds.iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "SOR")
        }))
    }

    /// [51] Wenn SG26 DTM+156 (Positionsbezogener Abrechnungszeitraum Ende) ≤ 1.1.2023 0:00 gesetzlicher deutscher Zeit
    // REVIEW: DTM+156 in SG26 (Positionsbezogener Abrechnungszeitraum Ende) uses format 303 (CCYYMMDDHHMM). January 1, 2023 at 00:00 = "202301010000". Without SG26-scoped group navigation, message-wide search is used; qualifier 156 in the SG26 context is distinct from the message-level 156, but without group navigation this is the best available approximation. (medium confidence)
    fn evaluate_51(&self, ctx: &EvaluationContext) -> ConditionResult {
        let dtm_segs = ctx.find_segments_with_qualifier("DTM", 0, "156");
        match dtm_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() => {
                        // Format 303 = CCYYMMDDHHMM; 1.1.2023 0:00 = "202301010000"
                        ConditionResult::from(value <= "202301010000")
                    }
                    _ => ConditionResult::Unknown,
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

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

    /// [54] Wenn IMD++ABR/JVR/ZVR vorhanden
    fn evaluate_54(&self, ctx: &EvaluationContext) -> ConditionResult {
        {
            let segs = ctx.find_segments("IMD");
            if segs.is_empty() {
                return ConditionResult::False;
            }
            ConditionResult::from(segs.iter().any(|s| {
                s.elements
                    .get(1)
                    .and_then(|e| e.first())
                    .is_some_and(|v| matches!(v.as_str(), "ABR" | "JVR" | "ZVR"))
            }))
        }
    }

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

    /// [56] Wenn DTM+137 (Nachrichtendatum ≥ 1.1.2023 0:00 gesetzlicher deutscher Zeit
    // REVIEW: DTM+137 Nachrichtendatum >= 2023-01-01. Parses the date value (format 303 = YYYYMMDDHHmm) and compares the first 8 characters against '20230101'. String comparison is valid for ISO date format. (medium confidence)
    fn evaluate_56(&self, ctx: &EvaluationContext) -> ConditionResult {
        {
            let segs = ctx.find_segments_with_qualifier("DTM", 0, "137");
            match segs.first() {
                Some(dtm) => match dtm.elements.first().and_then(|e| e.get(1)) {
                    Some(val) if val.len() >= 8 => {
                        ConditionResult::from(val[..8].cmp("20230101") != std::cmp::Ordering::Less)
                    }
                    _ => ConditionResult::Unknown,
                },
                None => ConditionResult::False, // segment absent → condition not applicable
            }
        }
    }

    /// [57] Wenn DTM+156 (Abrechnungszeitraum Ende) ≤ 1.1.2023 0:00 gesetzlicher deutscher Zeit
    // REVIEW: DTM+156 (Abrechnungszeitraum Ende) <= 2023-01-01 0:00. Compares first 8 chars of date value against '20230101'. Returns True when the end date is on or before Jan 1 2023. (medium confidence)
    fn evaluate_57(&self, ctx: &EvaluationContext) -> ConditionResult {
        {
            let segs = ctx.find_segments_with_qualifier("DTM", 0, "156");
            match segs.first() {
                Some(dtm) => match dtm.elements.first().and_then(|e| e.get(1)) {
                    Some(val) if val.len() >= 8 => ConditionResult::from(
                        val[..8].cmp("20230101") != std::cmp::Ordering::Greater,
                    ),
                    _ => ConditionResult::Unknown,
                },
                None => ConditionResult::False, // segment absent → condition not applicable
            }
        }
    }

    /// [58] Wenn in dieser SG52 MOA+113 vorhanden
    fn evaluate_58(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualifier("MOA", 0, "113", &["SG52"])
    }

    /// [59] Wenn SG26 DTM+155 (Positionsbezogener Abrechnungszeitraum Beginn) ≥ 1.1.2023 0:00 gesetzlicher deutscher Zeit
    // REVIEW: SG26 DTM+155 (Positionsbezogener Abrechnungszeitraum Beginn) >= 2023-01-01 0:00. Finds DTM with qualifier 155 and compares first 8 chars of the date value against '20230101'. (medium confidence)
    fn evaluate_59(&self, ctx: &EvaluationContext) -> ConditionResult {
        {
            let segs = ctx.find_segments_with_qualifier("DTM", 0, "155");
            match segs.first() {
                Some(dtm) => match dtm.elements.first().and_then(|e| e.get(1)) {
                    Some(val) if val.len() >= 8 => {
                        ConditionResult::from(val[..8].cmp("20230101") != std::cmp::Ordering::Less)
                    }
                    _ => ConditionResult::Unknown,
                },
                None => ConditionResult::False, // segment absent → condition not applicable
            }
        }
    }

    /// [60] Wenn DTM+203 DE2379 in demselben Segment mit Wert 303 vorhanden
    fn evaluate_60(&self, ctx: &EvaluationContext) -> ConditionResult {
        ConditionResult::from(ctx.self_segment_value_equals("DTM", 0, 2, "303"))
    }

    /// [61] Wenn DTM+203 DE2379 in demselben Segment mit Wert 102 vorhanden
    fn evaluate_61(&self, ctx: &EvaluationContext) -> ConditionResult {
        ConditionResult::from(ctx.self_segment_value_equals("DTM", 0, 2, "102"))
    }

    /// [64] Wenn DTM+156 (Abrechnungszeitraum Ende) ≤ 1.1.2024 0:00 gesetzlicher deutscher Zeit
    // REVIEW: DTM+156 (Abrechnungszeitraum Ende) <= 2024-01-01 0:00. Same pattern as condition 57 but with threshold '20240101'. (medium confidence)
    fn evaluate_64(&self, ctx: &EvaluationContext) -> ConditionResult {
        {
            let segs = ctx.find_segments_with_qualifier("DTM", 0, "156");
            match segs.first() {
                Some(dtm) => match dtm.elements.first().and_then(|e| e.get(1)) {
                    Some(val) if val.len() >= 8 => ConditionResult::from(
                        val[..8].cmp("20240101") != std::cmp::Ordering::Greater,
                    ),
                    _ => ConditionResult::Unknown,
                },
                None => ConditionResult::False, // segment absent → condition not applicable
            }
        }
    }

    /// [65] Wenn SG26 DTM+155 (Positionsbezogener Abrechnungszeitraum Beginn) ≥ 1.1.2024 0:00 gesetzlicher deutscher Zeit
    // REVIEW: SG26 DTM+155 (Positionsbezogener Abrechnungszeitraum Beginn) >= 2024-01-01 0:00. Same pattern as condition 59 but with threshold '20240101'. (medium confidence)
    fn evaluate_65(&self, ctx: &EvaluationContext) -> ConditionResult {
        {
            let segs = ctx.find_segments_with_qualifier("DTM", 0, "155");
            match segs.first() {
                Some(dtm) => match dtm.elements.first().and_then(|e| e.get(1)) {
                    Some(val) if val.len() >= 8 => {
                        ConditionResult::from(val[..8].cmp("20240101") != std::cmp::Ordering::Less)
                    }
                    _ => ConditionResult::Unknown,
                },
                None => ConditionResult::False, // segment absent → condition not applicable
            }
        }
    }

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

    /// [70] Wenn IMD++Z45 nicht vorhanden
    fn evaluate_70(&self, ctx: &EvaluationContext) -> ConditionResult {
        let imd_segments = ctx.find_segments("IMD");
        let found = imd_segments.iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z45")
        });
        ConditionResult::from(!found)
    }

    /// [71] Wenn DTM+155 (Abrechnungszeitraum Beginn) ≥ 1.1.2024 0:00 gesetzlicher deutscher Zeit
    // REVIEW: DTM+155 means elements[0][0]=="155". Value is at elements[0][1] in 303 format (YYYYMMDDhhmm). String comparison works for chronological ordering. Timezone nuance (German legal time) ignored — medium confidence. (medium confidence)
    fn evaluate_71(&self, ctx: &EvaluationContext) -> ConditionResult {
        let dtm_segments = ctx.find_segments_with_qualifier("DTM", 0, "155");
        match dtm_segments.first() {
            Some(dtm) => {
                match dtm
                    .elements
                    .first()
                    .and_then(|e| e.get(1))
                    .map(|s| s.as_str())
                {
                    Some(value) if !value.is_empty() => {
                        // 303 format: YYYYMMDDhhmm — lexicographic comparison is chronological for zero-padded strings
                        ConditionResult::from(value >= "202401010000")
                    }
                    _ => ConditionResult::Unknown,
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [72] Wenn MP-ID in NAD+MR in der Rolle LF
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Whether the MP-ID in NAD+MR has the market role LF (Lieferant) cannot be determined from the EDIFACT message alone — it requires a business registry lookup. The NAD+MR segment only provides the party identifier, not the assigned market role. (medium confidence)
    fn evaluate_72(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("recipient_is_lf")
    }

    /// [73] Wenn IMD++MSB vorhanden
    fn evaluate_73(&self, ctx: &EvaluationContext) -> ConditionResult {
        let imd_segments = ctx.find_segments("IMD");
        let found = imd_segments.iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "MSB")
        });
        ConditionResult::from(found)
    }

    /// [74] wenn im DE3155 in demselben COM der Code EM vorhanden ist
    fn evaluate_74(&self, ctx: &EvaluationContext) -> ConditionResult {
        let com_segments = ctx.find_segments("COM");
        let found = com_segments.iter().any(|s| {
            s.elements
                .first()
                .and_then(|e| e.get(1))
                .is_some_and(|v| v == "EM")
        });
        ConditionResult::from(found)
    }

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

    /// [76] Wenn MP-ID in NAD+MR in der Rolle NB
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Whether the MP-ID in NAD+MR has the market role NB (Netzbetreiber) cannot be determined from the EDIFACT message alone — it requires a business registry lookup. The NAD+MR segment only provides the party identifier, not the assigned market role. (medium confidence)
    fn evaluate_76(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("recipient_is_nb")
    }

    /// [77] Wenn SG26 DTM+156 (Positionsbezogener Abrechnungszeitraum Ende) ≤ 1.1.2024 0:00 gesetzlicher deutscher Zeit
    // REVIEW: SG26 DTM+156 means elements[0][0]=="156". Value at elements[0][1] in 303 format. Compare <= "202401010000" (Jan 1 2024 00:00). Medium confidence due to timezone nuance. (medium confidence)
    fn evaluate_77(&self, ctx: &EvaluationContext) -> ConditionResult {
        let dtm_segments = ctx.find_segments_with_qualifier("DTM", 0, "156");
        match dtm_segments.first() {
            Some(dtm) => {
                match dtm
                    .elements
                    .first()
                    .and_then(|e| e.get(1))
                    .map(|s| s.as_str())
                {
                    Some(value) if !value.is_empty() => {
                        // 303 format: YYYYMMDDhhmm — lexicographic comparison is chronological
                        ConditionResult::from(value <= "202401010000")
                    }
                    _ => ConditionResult::Unknown,
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [78] Wenn GEI+Z08 nicht vorhanden
    // REVIEW: GEI schema shows elements[0] qualifier is always Z01, while the specification code is at elements[1][0] (DE7365) with codes Z01-Z06 +3 more. 'GEI+Z08' in AHB shorthand refers to elements[1][0]=="Z08". Absence check returns True when not found. (medium confidence)
    fn evaluate_78(&self, ctx: &EvaluationContext) -> ConditionResult {
        let found = ctx.find_segments("GEI").iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z08")
        });
        ConditionResult::from(!found)
    }

    /// [79] Wenn GEI+Z09 nicht vorhanden
    // REVIEW: Same pattern as condition 78. 'GEI+Z09' in AHB shorthand refers to elements[1][0]=="Z09". (medium confidence)
    fn evaluate_79(&self, ctx: &EvaluationContext) -> ConditionResult {
        let found = ctx.find_segments("GEI").iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z09")
        });
        ConditionResult::from(!found)
    }

    /// [80] Wenn GEI+Z01 nicht vorhanden
    // REVIEW: 'GEI+Z01' refers to elements[1][0]=="Z01" (the specification code, not the fixed qualifier at elements[0]). Absence check. (medium confidence)
    fn evaluate_80(&self, ctx: &EvaluationContext) -> ConditionResult {
        let found = ctx.find_segments("GEI").iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z01")
        });
        ConditionResult::from(!found)
    }

    /// [81] Wenn GEI+Z04 nicht vorhanden
    // REVIEW: Same pattern as condition 78. 'GEI+Z04' refers to elements[1][0]=="Z04". (medium confidence)
    fn evaluate_81(&self, ctx: &EvaluationContext) -> ConditionResult {
        let found = ctx.find_segments("GEI").iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z04")
        });
        ConditionResult::from(!found)
    }

    /// [82] Wenn GEI+Z05 nicht vorhanden
    // REVIEW: Same pattern as condition 78. 'GEI+Z05' refers to elements[1][0]=="Z05". (medium confidence)
    fn evaluate_82(&self, ctx: &EvaluationContext) -> ConditionResult {
        let found = ctx.find_segments("GEI").iter().any(|s| {
            s.elements
                .get(1)
                .and_then(|e| e.first())
                .is_some_and(|v| v == "Z05")
        });
        ConditionResult::from(!found)
    }

    /// [84] Wenn in dieser SG39 ALC+C+:Z02 / Z03 / Z04 vorhanden
    fn evaluate_84(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.any_group_has_qualified_value("ALC", 0, "C", 1, 1, &["Z02", "Z03", "Z04"], &["SG39"])
    }

    /// [85] Wenn in diesem Segment DE6411 = DAY
    // REVIEW: DE6411 is the measurement unit code, appearing in QTY segments as C186 composite: elements[0][0]=DE6063 (qualifier), elements[0][1]=DE6060 (quantity), elements[0][2]=DE6411 (unit code). 'DAY' is the unit code for daily quantities. Medium confidence as the specific segment context ('in diesem Segment') may require group scoping. (medium confidence)
    fn evaluate_85(&self, ctx: &EvaluationContext) -> ConditionResult {
        let qty_segments = ctx.find_segments("QTY");
        let found = qty_segments.iter().any(|s| {
            s.elements
                .first()
                .and_then(|e| e.get(2))
                .is_some_and(|v| v == "DAY")
        });
        ConditionResult::from(found)
    }

    /// [86] Wenn in diesem Segment DE6411 = MON/ANN
    // REVIEW: DE6411 is the unit of measure code in QTY segments at elements[0][2] (C186 component 2). 'In diesem Segment' means within the current QTY context. Check message-wide for QTY with MON or ANN unit code. (medium confidence)
    fn evaluate_86(&self, ctx: &EvaluationContext) -> ConditionResult {
        let qty_segments = ctx.find_segments("QTY");
        ConditionResult::from(qty_segments.iter().any(|s| {
            s.elements
                .first()
                .and_then(|e| e.get(2))
                .map(|v| v == "MON" || v == "ANN")
                .unwrap_or(false)
        }))
    }

    /// [88] Wenn DTM+155 (Abrechnungszeitraum Beginn) ≥ 1.1.2026 0:00 gesetzlicher deutscher Zeit
    fn evaluate_88(&self, ctx: &EvaluationContext) -> ConditionResult {
        let dtm_segs = ctx.find_segments_with_qualifier("DTM", 0, "155");
        match dtm_segs.first() {
            Some(dtm) => {
                match dtm
                    .elements
                    .first()
                    .and_then(|e| e.get(1))
                    .map(|s| s.as_str())
                {
                    Some(value) if value.len() >= 8 => {
                        let date_part = &value[..8];
                        ConditionResult::from(date_part >= "20260101")
                    }
                    _ => ConditionResult::Unknown,
                }
            }
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

    /// [492] Wenn MP-ID in NAD+MR (Nachrichtenempfänger) aus Sparte Strom
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Checks whether the NAD+MR (message recipient) MP-ID belongs to the electricity (Strom) sector. The NAD+MR element structure is known (elements[0]=MR, elements[1][0]=MP-ID), but sector membership cannot be determined from the EDIFACT message content alone — it requires an external market participant registry. Delegated to external provider. (medium confidence)
    fn evaluate_492(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("recipient_is_strom")
    }

    /// [493] Wenn MP-ID in NAD+MR (Nachrichtenempfänger) aus Sparte Gas
    /// EXTERNAL: Requires context from outside the message.
    // REVIEW: Checks whether the NAD+MR (message recipient) MP-ID belongs to the gas (Gas) sector. Same reasoning as 492 — sector membership cannot be determined from the EDIFACT message alone; requires external market participant registry. Delegated to external provider. (medium confidence)
    fn evaluate_493(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.external.evaluate("recipient_is_gas")
    }

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

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

    /// [503] Hinweis: Ein positiver Betrag ist eine Forderung des Rechnungsstellers.
    fn evaluate_503(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Ein positiver Betrag ist eine Forderung des Rechnungsstellers — informational note, always applies
        ConditionResult::True
    }

    /// [504] Hinweis: Ein positiver Betrag ist eine Forderung des Rechnungsempfängers.
    fn evaluate_504(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Ein positiver Betrag ist eine Forderung des Rechnungsempfängers — informational note, always applies
        ConditionResult::True
    }

    /// [507] Hinweis: Dokumentennummer der SSQNOT
    fn evaluate_507(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Dokumentennummer der SSQNOT — informational note, always applies
        ConditionResult::True
    }

    /// [508] Hinweis: Dokumentennummer der QUOTES
    fn evaluate_508(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Dokumentennummer der QUOTES — informational note, always applies
        ConditionResult::True
    }

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

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

    /// [512] Hinweis: Hier ist entweder der Betrag aus MOA+203 oder der um den gültigen Steuerbetrag erhöhte Betrag aus MOA+203 anzugeben.
    fn evaluate_512(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Hier ist entweder der Betrag aus MOA+203 oder der um den gültigen Steuerbetrag erhöhte Betrag aus MOA+203 anzugeben — informational note, always applies
        ConditionResult::True
    }

    /// [513] Hinweis: Hier ist das Ergebnis der Multiplikation von MOA+25 mit PCD+3 anzugeben.
    fn evaluate_513(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Hier ist das Ergebnis der Multiplikation von MOA+25 mit PCD+3 anzugeben — informational note, always applies
        ConditionResult::True
    }

    /// [514] Hinweis: Dokumentennummer der Lieferschein-MSCONS
    fn evaluate_514(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Dokumentennummer der Lieferschein-MSCONS — informational note, always applies
        ConditionResult::True
    }

    /// [515] Hinweis: BGM DE1004 aus INVOIC-Nachricht, die storniert werden soll
    fn evaluate_515(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: BGM DE1004 aus INVOIC-Nachricht, die storniert werden soll — informational note, always applies
        ConditionResult::True
    }

    /// [516] Hinweis: Ein Lieferschein zu einer Rechnung ist für alle Abrechnungszeiträume, die erstmals nach dem 1.12.2019 abgerechnet werden und für alle Abrechnungszeiträume, für die sich nach dem 1.12....
    fn evaluate_516(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Ein Lieferschein zu einer Rechnung ist für alle Abrechnungszeiträume, die erstmals nach dem 1.12.2019 abgerechnet werden und für alle Abrechnungszeiträume, für die sich nach dem 1.12.2019 geänderte Mengen oder Leistungswerte ergeben, nötig.
        ConditionResult::True
    }

    /// [517] Hinweis: Dokumentennummer der PDF-Kapazitätsrechnung
    fn evaluate_517(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Dokumentennummer der PDF-Kapazitätsrechnung — informational annotation, always applies
        ConditionResult::True
    }

    /// [518] Hinweis:  Im Fall der Stornierung des Auftrags der Unterbrechung: Der Tag an dem der NB die Stornierung empfangen hat Bei erfolgreicher Sperrung: Tag der durchgeführten Sperrung Bei erfolgloser Sp...
    fn evaluate_518(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Date semantics for cancellation/blocking scenarios — informational annotation, always applies
        ConditionResult::True
    }

    /// [519] Hinweis: Stornierte Abschlagsrechnungen sind nicht aufzuführen
    fn evaluate_519(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Stornierte Abschlagsrechnungen sind nicht aufzuführen — informational annotation, always applies
        ConditionResult::True
    }

    /// [520] Hinweis: Es sind nur die Artikel-IDs aus dem Preisblatt erlaubt
    fn evaluate_520(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Es sind nur die Artikel-IDs aus dem Preisblatt erlaubt — informational annotation, always applies
        ConditionResult::True
    }

    /// [521] Hinweis: BGM DE1004 aus der INVOIC-Nachricht, für die Verzugskosten erhoben werden
    fn evaluate_521(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: BGM DE1004 aus der INVOIC-Nachricht, für die Verzugskosten erhoben werden — informational note, always applies
        ConditionResult::True
    }

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

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

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

    /// [525] Hinweis: Verwendung, sofern Netzentgelte geringer als die Pauschale Netzentgeltreduzierung
    fn evaluate_525(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Verwendung, sofern Netzentgelte geringer als die Pauschale Netzentgeltreduzierung — informational note, always applies
        ConditionResult::True
    }

    /// [526] Hinweis: Der hier angegebene Geldbetrag muss mit dem identisch sein, der in SG50 MOA+77 im DE5004 der Abschlagsrechnung steht, die die Rechnungsnummer hat, die in dieser SG50 in SG51-RFF+AFL in DE1...
    fn evaluate_526(&self, _ctx: &EvaluationContext) -> ConditionResult {
        // Hinweis: Der hier angegebene Geldbetrag muss mit dem identisch sein, der in SG50 MOA+77
        // im DE5004 der Abschlagsrechnung steht, die die Rechnungsnummer hat, die in dieser SG50
        // in SG51-RFF+AFL in DE1154 genannt ist.
        // Informational note — always applies
        ConditionResult::True
    }

    /// [902] Format: Möglicher Wert: ≥ 0
    // REVIEW: Format condition requiring value >= 0, applied to MOA amount (DE5004 at elements[0][1]). Medium confidence because exact segment/group context is inferred from INVOIC structure — the full AHB table row would clarify which specific MOA qualifier this applies to. (medium confidence)
    fn evaluate_902(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("MOA", 0, 1, |val| validate_numeric(val, ">=", 0.0))
    }

    /// [906] Format: max. 3 Nachkommastellen
    // REVIEW: Format condition requiring at most 3 decimal places. Most likely applies to MOA DE5004 (Geldbetrag) in INVOIC. Medium confidence — the exact MOA qualifier or group (SG27/SG42/SG50/SG52) depends on the AHB table row context not included in the condition description alone. (medium confidence)
    fn evaluate_906(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("MOA", 0, 1, |val| validate_max_decimal_places(val, 3))
    }

    /// [908] Format: Mögliche Werte: 1 bis n
    // REVIEW: Format condition requiring value in range 1..n (strictly positive). Applied to QTY quantity values in INVOIC (DE6060 at elements[0][1]). Medium confidence — the exact segment context depends on the full AHB table row. (medium confidence)
    fn evaluate_908(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("QTY", 0, 1, |val| validate_numeric(val, ">=", 1.0))
    }

    /// [910] Format: Möglicher Wert: &lt; 0 oder ≥ 0
    // REVIEW: Format condition accepting any numeric value (< 0 OR >= 0 is universally true). This documents that the field accepts negative values (unlike condition 902 which restricts to >= 0). Validates the value is a parseable number. Medium confidence on the exact segment — likely a MOA that can be a credit/deduction amount. (medium confidence)
    fn evaluate_910(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Format: Möglicher Wert: < 0 oder ≥ 0 — any numeric value is valid (no sign constraint)
        // Applied to MOA amounts that may be negative (e.g., credits, deductions)
        let segs = ctx.find_segments("MOA");
        match segs
            .first()
            .and_then(|s| s.elements.first())
            .and_then(|e| e.get(1))
        {
            Some(val) if !val.is_empty() => {
                // < 0 or >= 0 covers all real numbers — validate it is a parseable number
                match val.trim_start_matches('-').parse::<f64>() {
                    Ok(_) => ConditionResult::True,
                    Err(_) => ConditionResult::False,
                }
            }
            _ => ConditionResult::Unknown,
        }
    }

    /// [911] Format: Mögliche Werte: 1 bis n, je Nachricht oder Segmentgruppe bei 1 beginnend und fortlaufend aufsteigend
    // REVIEW: Sequential numbering validation (1 to n, ascending) — only the >= 1 integer constraint can be checked on a single value. Full sequential ordering cannot be verified without stateful iteration across all instances. Applies to LIN line item numbers in INVOIC SG26. Medium confidence due to segment assumption and inability to verify sequential ordering in isolation. (medium confidence)
    fn evaluate_911(&self, ctx: &EvaluationContext) -> ConditionResult {
        // Format: Mögliche Werte: 1 bis n, je Nachricht oder Segmentgruppe bei 1 beginnend und fortlaufend aufsteigend
        // Validates that the value is a positive integer >= 1 (sequential enforcement requires external state)
        let segs = ctx.find_segments("LIN");
        match segs
            .first()
            .and_then(|s| s.elements.first())
            .and_then(|e| e.first())
        {
            Some(val) => match val.parse::<i64>() {
                Ok(n) if n >= 1 => ConditionResult::True,
                Ok(_) => ConditionResult::False,
                Err(_) => ConditionResult::False,
            },
            None => ConditionResult::False, // segment absent → condition not applicable
        }
    }

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

    /// [927] Format: Möglicher Wert: -1
    // REVIEW: Value must be exactly -1. Used for special indicator values (e.g., a reversal or placeholder quantity). validate_numeric with == operator handles exact match. Medium confidence due to segment assumption — the -1 constraint is unusual and the exact segment context (QTY vs MOA) depends on which AHB data element references this condition. (medium confidence)
    fn evaluate_927(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("QTY", 0, 1, |val| validate_numeric(val, "==", -1.0))
    }

    /// [930] Format: max. 2 Nachkommastellen
    fn evaluate_930(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("QTY", 0, 1, |val| validate_max_decimal_places(val, 2))
    }

    /// [931] Format: ZZZ = +00
    fn evaluate_931(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("DTM", 0, 1, validate_timezone_utc)
    }

    /// [932] Format: HHMM = 2200
    fn evaluate_932(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("DTM", 0, 1, |val| validate_hhmm_equals(val, "2200"))
    }

    /// [933] Format: HHMM = 2300
    fn evaluate_933(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("DTM", 0, 1, |val| validate_hhmm_equals(val, "2300"))
    }

    /// [934] Format: HHMM = 0400
    fn evaluate_934(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("DTM", 0, 1, |val| validate_hhmm_equals(val, "0400"))
    }

    /// [935] Format: HHMM = 0500
    fn evaluate_935(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("DTM", 0, 1, |val| validate_hhmm_equals(val, "0500"))
    }

    /// [937] Format: keine Nachkommastelle
    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
    fn evaluate_939(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("COM", 0, 0, validate_email)
    }

    /// [940] Format: Die Zeichenkette muss mit dem Zeichen + beginnen und danach dürfen nur noch Ziffern folgen
    fn evaluate_940(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check("COM", 0, 0, validate_phone)
    }

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

    /// [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
    fn evaluate_960(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check_qualified("LOC", 0, "Z18", 1, 0, validate_malo_id)
    }

    /// [961] Format: SR-ID
    fn evaluate_961(&self, ctx: &EvaluationContext) -> ConditionResult {
        ctx.format_check_qualified("LOC", 0, "Z19", 1, 0, validate_malo_id)
    }
}