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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
"""

Task definitions and synthetic case templates for InvoiceGuard.



Four tasks with increasing difficulty, each with fully synthetic

business documents and deterministic ground truth.

"""

from typing import Dict, List

try:
    from ..models import (
        CaseData, CaseHistory, CompanyPolicy, DecisionType, Difficulty,
        ExceptionType, GRNLineItem, GoodsReceiptNote, GroundTruth,
        Invoice, InvoiceLineItem, POLineItem, PurchaseOrder,
        TaskID, VendorProfile,
    )
    from .hard_definitions import HARD_TASK_BUILDERS, HARD_TASK_LIST
except ImportError:
    from models import (
        CaseData, CaseHistory, CompanyPolicy, DecisionType, Difficulty,
        ExceptionType, GRNLineItem, GoodsReceiptNote, GroundTruth,
        Invoice, InvoiceLineItem, POLineItem, PurchaseOrder,
        TaskID, VendorProfile,
    )
    from tasks.hard_definitions import HARD_TASK_BUILDERS, HARD_TASK_LIST


TASK_LIST: List[TaskID] = [
    TaskID.task_1_clean_match,
    TaskID.task_2_partial_receipt,
    TaskID.task_3_price_variance,
    TaskID.task_4_duplicate_invoice,
    TaskID.task_5_mixed_discrepancy,
    TaskID.task_6_false_positive_duplicate,
    TaskID.task_7_retroactive_price,
    TaskID.task_8_split_invoice_pattern,
    TaskID.task_9_clean_from_risky_vendor,
    TaskID.task_10_rounding_false_alarm,
    TaskID.task_11_authorized_overship,
    TaskID.task_12_corrected_resubmission,
]

ALL_TASKS: List[TaskID] = [
    TaskID.task_1_clean_match,
    TaskID.task_1b_multi_line_clean,
    TaskID.task_1c_preferred_vendor_clean,
    TaskID.task_2_partial_receipt,
    TaskID.task_2b_missing_receipt,
    TaskID.task_2c_over_receipt,
    TaskID.task_3_price_variance,
    TaskID.task_3b_within_tolerance,
    TaskID.task_3c_total_mismatch,
    TaskID.task_4_duplicate_invoice,
    TaskID.task_4b_corrected_invoice_trap,
    TaskID.task_4c_policy_violation,
    TaskID.task_5_mixed_discrepancy,
    TaskID.task_6_false_positive_duplicate,
    TaskID.task_7_retroactive_price,
    TaskID.task_8_split_invoice_pattern,
    TaskID.task_9_clean_from_risky_vendor,
    TaskID.task_10_rounding_false_alarm,
    TaskID.task_11_authorized_overship,
    TaskID.task_12_corrected_resubmission,
    *HARD_TASK_LIST,
]


def get_task_case(task_id: TaskID) -> CaseData:
    """Return the case data for a given task (canonical or variant)."""
    builders: Dict[TaskID, callable] = {
        TaskID.task_1_clean_match: _build_task_1,
        TaskID.task_1b_multi_line_clean: _build_task_1b,
        TaskID.task_1c_preferred_vendor_clean: _build_task_1c,
        TaskID.task_2_partial_receipt: _build_task_2,
        TaskID.task_2b_missing_receipt: _build_task_2b,
        TaskID.task_2c_over_receipt: _build_task_2c,
        TaskID.task_3_price_variance: _build_task_3,
        TaskID.task_3b_within_tolerance: _build_task_3b,
        TaskID.task_3c_total_mismatch: _build_task_3c,
        TaskID.task_4_duplicate_invoice: _build_task_4,
        TaskID.task_4b_corrected_invoice_trap: _build_task_4b,
        TaskID.task_4c_policy_violation: _build_task_4c,
        TaskID.task_5_mixed_discrepancy: _build_task_5,
        TaskID.task_6_false_positive_duplicate: _build_task_6,
        TaskID.task_7_retroactive_price: _build_task_7,
        TaskID.task_8_split_invoice_pattern: _build_task_8,
        TaskID.task_9_clean_from_risky_vendor: _build_task_9,
        TaskID.task_10_rounding_false_alarm: _build_task_10,
        TaskID.task_11_authorized_overship: _build_task_11,
        TaskID.task_12_corrected_resubmission: _build_task_12,
        **HARD_TASK_BUILDERS,
    }
    return builders[task_id]()


# -- Task 1: Clean Match Approval --------------------------------------------
# Difficulty: easy | Decision: approve_for_payment | Exception: clean_match
# All three documents align within tolerance. Tests whether the agent can
# confirm a clean case without inventing problems.


def _build_task_1() -> CaseData:
    return CaseData(
        case_id="CASE-1001",
        task_id=TaskID.task_1_clean_match,
        difficulty=Difficulty.easy,
        max_steps=10,
        invoice=Invoice(
            invoice_number="INV-2024-0042",
            supplier_name="Apex Office Supplies",
            supplier_id="SUP-1001",
            invoice_date="2024-11-15",
            po_reference="PO-5500",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-A01",
                    description="Premium Copy Paper A4 (500 sheets)",
                    quantity_billed=100,
                    unit_price_billed=25.00,
                    line_total_billed=2500.00,
                ),
            ],
            subtotal=2500.00,
            tax=200.00,
            total_amount=2700.00,
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-5500",
            supplier_id="SUP-1001",
            order_date="2024-10-20",
            line_items=[
                POLineItem(
                    item_code="ITEM-A01",
                    description="Premium Copy Paper A4 (500 sheets)",
                    ordered_quantity=100,
                    unit_price_ordered=25.00,
                    line_total_ordered=2500.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-7801",
            po_reference="PO-5500",
            receipt_date="2024-11-10",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-A01",
                    quantity_received=100,
                    accepted_quantity=100,
                ),
            ],
            warehouse_note="All items received in good condition.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-1001",
            supplier_name="Apex Office Supplies",
            risk_tier="low",
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=100.0,
        ),
        case_history=CaseHistory(),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.approve_for_payment,
            correct_exception_type=ExceptionType.clean_match,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
            ],
            key_findings=[
                "Quantities match across invoice, PO, and GRN",
                "Prices match between invoice and PO",
                "No discrepancies detected",
            ],
        ),
    )


# -- Task 2: Quantity & Partial Receipt Hold ----------------------------------
# Difficulty: moderate | Decision: place_on_hold | Exception: partial_receipt
# Invoice bills 100 units, PO ordered 100, but GRN only received 60.
# Agent must recognize billed qty exceeds received qty.


def _build_task_2() -> CaseData:
    return CaseData(
        case_id="CASE-2002",
        task_id=TaskID.task_2_partial_receipt,
        difficulty=Difficulty.moderate,
        max_steps=10,
        invoice=Invoice(
            invoice_number="INV-2024-0187",
            supplier_name="Delta Industrial Parts",
            supplier_id="SUP-2050",
            invoice_date="2024-12-01",
            po_reference="PO-6200",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-D10",
                    description="Stainless Steel Bearings (Box of 50)",
                    quantity_billed=100,
                    unit_price_billed=50.00,
                    line_total_billed=5000.00,
                ),
            ],
            subtotal=5000.00,
            tax=400.00,
            total_amount=5400.00,
            note="Please process payment promptly.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-6200",
            supplier_id="SUP-2050",
            order_date="2024-11-01",
            line_items=[
                POLineItem(
                    item_code="ITEM-D10",
                    description="Stainless Steel Bearings (Box of 50)",
                    ordered_quantity=100,
                    unit_price_ordered=50.00,
                    line_total_ordered=5000.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-8830",
            po_reference="PO-6200",
            receipt_date="2024-11-25",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-D10",
                    quantity_received=60,
                    accepted_quantity=60,
                    rejected_quantity=0,
                ),
            ],
            warehouse_note="Partial shipment. Remaining 40 units expected next week.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-2050",
            supplier_name="Delta Industrial Parts",
            risk_tier="medium",
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=200.0,
        ),
        case_history=CaseHistory(
            prior_comments=["Supplier has had partial shipments before."],
        ),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.place_on_hold,
            correct_exception_type=ExceptionType.partial_receipt,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "compare_quantity",
            ],
            key_findings=[
                "Invoice billed 100 units but GRN shows only 60 received",
                "Billed quantity exceeds received quantity by 40 units (40%)",
                "Variance exceeds quantity tolerance of 5%",
            ],
        ),
    )


# -- Task 3: Price Variance with Policy Tolerance ----------------------------
# Difficulty: moderate | Decision: escalate_for_supervisor_review
# Exception: price_mismatch
# Invoice unit price is $110 vs PO price of $100 (10% variance).
# Company tolerance is 5%, so this must be escalated.


def _build_task_3() -> CaseData:
    return CaseData(
        case_id="CASE-3003",
        task_id=TaskID.task_3_price_variance,
        difficulty=Difficulty.moderate,
        max_steps=10,
        invoice=Invoice(
            invoice_number="INV-2024-0315",
            supplier_name="Quantum Tech Solutions",
            supplier_id="SUP-3100",
            invoice_date="2024-12-10",
            po_reference="PO-7100",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-Q22",
                    description="Enterprise SSD 1TB NVMe",
                    quantity_billed=50,
                    unit_price_billed=110.00,
                    line_total_billed=5500.00,
                ),
            ],
            subtotal=5500.00,
            tax=440.00,
            total_amount=5940.00,
            note="Price adjusted due to component shortage surcharge.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-7100",
            supplier_id="SUP-3100",
            order_date="2024-11-15",
            line_items=[
                POLineItem(
                    item_code="ITEM-Q22",
                    description="Enterprise SSD 1TB NVMe",
                    ordered_quantity=50,
                    unit_price_ordered=100.00,
                    line_total_ordered=5000.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-9150",
            po_reference="PO-7100",
            receipt_date="2024-12-05",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-Q22",
                    quantity_received=50,
                    accepted_quantity=50,
                ),
            ],
            warehouse_note="All units received and tested OK.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-3100",
            supplier_name="Quantum Tech Solutions",
            risk_tier="medium",
            preferred_vendor=True,
            escalation_threshold=5000.00,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=200.0,
            high_value_threshold=50000.0,
        ),
        case_history=CaseHistory(
            prior_comments=[
                "Supplier occasionally applies surcharges without prior notice.",
            ],
        ),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.escalate_for_supervisor_review,
            correct_exception_type=ExceptionType.price_mismatch,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_policy_rules",
                "compare_price",
            ],
            key_findings=[
                "Invoice unit price $110.00 vs PO unit price $100.00",
                "Price variance of 10% exceeds company tolerance of 5%",
                "Requires supervisor review per escalation policy",
            ],
        ),
    )


# -- Task 4: Duplicate Invoice with Mixed Signals ----------------------------
# Difficulty: hard | Decision: reject_invoice | Exception: duplicate_invoice
# Quantities and prices match perfectly, but case history reveals a
# previously processed invoice with near-identical details. A misleading
# vendor note tries to distract.


def _build_task_4() -> CaseData:
    return CaseData(
        case_id="CASE-4004",
        task_id=TaskID.task_4_duplicate_invoice,
        difficulty=Difficulty.hard,
        max_steps=12,
        invoice=Invoice(
            invoice_number="INV-2024-0512",
            supplier_name="Redline Logistics Corp",
            supplier_id="SUP-4200",
            invoice_date="2024-12-18",
            po_reference="PO-8800",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-R05",
                    description="Heavy-Duty Shipping Pallets",
                    quantity_billed=200,
                    unit_price_billed=30.00,
                    line_total_billed=6000.00,
                ),
            ],
            subtotal=6000.00,
            tax=480.00,
            total_amount=6480.00,
            note="URGENT: Payment overdue. Please expedite. Ref: follow-up to INV-2024-0511.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-8800",
            supplier_id="SUP-4200",
            order_date="2024-11-20",
            line_items=[
                POLineItem(
                    item_code="ITEM-R05",
                    description="Heavy-Duty Shipping Pallets",
                    ordered_quantity=200,
                    unit_price_ordered=30.00,
                    line_total_ordered=6000.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-9900",
            po_reference="PO-8800",
            receipt_date="2024-12-12",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-R05",
                    quantity_received=200,
                    accepted_quantity=200,
                ),
            ],
            warehouse_note="Full shipment received.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-4200",
            supplier_name="Redline Logistics Corp",
            risk_tier="high",
            duplicate_risk_count=2,
            preferred_vendor=False,
            escalation_threshold=3000.00,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=200.0,
            duplicate_check_enabled=True,
        ),
        case_history=CaseHistory(
            prior_comments=[
                "Previous duplicate submission flagged for this supplier in Q3.",
                "Supplier has been warned about duplicate invoicing.",
            ],
            similar_invoice_refs=["INV-2024-0511"],
            processed_invoice_numbers=[
                "INV-2024-0511",
                "INV-2024-0388",
            ],
        ),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.reject_invoice,
            correct_exception_type=ExceptionType.duplicate_invoice,
            acceptable_evidence=[
                "check_for_duplicate_invoice",
                "inspect_vendor_profile",
            ],
            key_findings=[
                "Previously processed INV-2024-0511 has same supplier, same PO, same total",
                "Current invoice INV-2024-0512 is sequential to processed INV-2024-0511",
                "Supplier flagged as high risk with 2 prior duplicate incidents",
                "Invoice note references INV-2024-0511 as 'follow-up'",
            ],
        ),
    )


# ===========================================================================
# VARIANT TASKS
# ===========================================================================


# -- Task 1b: Multi-Line Clean Match --------------------------------------
# Three line items, all matching. Tests multi-item verification.

def _build_task_1b() -> CaseData:
    return CaseData(
        case_id="CASE-1002",
        task_id=TaskID.task_1b_multi_line_clean,
        difficulty=Difficulty.easy,
        max_steps=10,
        invoice=Invoice(
            invoice_number="INV-2024-0099",
            supplier_name="Summit Facility Services",
            supplier_id="SUP-1050",
            invoice_date="2024-11-20",
            po_reference="PO-5510",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-F01",
                    description="Industrial Floor Cleaner 5L",
                    quantity_billed=20,
                    unit_price_billed=35.00,
                    line_total_billed=700.00,
                ),
                InvoiceLineItem(
                    item_code="ITEM-F02",
                    description="Microfiber Mop Heads (Pack of 10)",
                    quantity_billed=15,
                    unit_price_billed=18.00,
                    line_total_billed=270.00,
                ),
                InvoiceLineItem(
                    item_code="ITEM-F03",
                    description="Nitrile Gloves Box (100ct)",
                    quantity_billed=50,
                    unit_price_billed=12.00,
                    line_total_billed=600.00,
                ),
            ],
            subtotal=1570.00,
            tax=125.60,
            total_amount=1695.60,
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-5510",
            supplier_id="SUP-1050",
            order_date="2024-10-25",
            line_items=[
                POLineItem(
                    item_code="ITEM-F01",
                    description="Industrial Floor Cleaner 5L",
                    ordered_quantity=20,
                    unit_price_ordered=35.00,
                    line_total_ordered=700.00,
                ),
                POLineItem(
                    item_code="ITEM-F02",
                    description="Microfiber Mop Heads (Pack of 10)",
                    ordered_quantity=15,
                    unit_price_ordered=18.00,
                    line_total_ordered=270.00,
                ),
                POLineItem(
                    item_code="ITEM-F03",
                    description="Nitrile Gloves Box (100ct)",
                    ordered_quantity=50,
                    unit_price_ordered=12.00,
                    line_total_ordered=600.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-7820",
            po_reference="PO-5510",
            receipt_date="2024-11-15",
            line_items=[
                GRNLineItem(item_code="ITEM-F01", quantity_received=20, accepted_quantity=20),
                GRNLineItem(item_code="ITEM-F02", quantity_received=15, accepted_quantity=15),
                GRNLineItem(item_code="ITEM-F03", quantity_received=50, accepted_quantity=50),
            ],
            warehouse_note="All items received, inspected, shelved.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-1050",
            supplier_name="Summit Facility Services",
            risk_tier="low",
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=100.0,
        ),
        case_history=CaseHistory(),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.approve_for_payment,
            correct_exception_type=ExceptionType.clean_match,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
            ],
            key_findings=[
                "All 3 line items match across invoice, PO, and GRN",
                "No price or quantity discrepancies",
            ],
        ),
    )


# -- Task 1c: Preferred Vendor Clean Match --------------------------------
# Single item, low-risk preferred vendor, very straightforward.

def _build_task_1c() -> CaseData:
    return CaseData(
        case_id="CASE-1003",
        task_id=TaskID.task_1c_preferred_vendor_clean,
        difficulty=Difficulty.easy,
        max_steps=10,
        invoice=Invoice(
            invoice_number="INV-2024-0155",
            supplier_name="BrightStar IT Solutions",
            supplier_id="SUP-1200",
            invoice_date="2024-12-02",
            po_reference="PO-5600",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-B10",
                    description="Wireless Keyboard & Mouse Combo",
                    quantity_billed=30,
                    unit_price_billed=45.00,
                    line_total_billed=1350.00,
                ),
            ],
            subtotal=1350.00,
            tax=108.00,
            total_amount=1458.00,
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-5600",
            supplier_id="SUP-1200",
            order_date="2024-11-10",
            line_items=[
                POLineItem(
                    item_code="ITEM-B10",
                    description="Wireless Keyboard & Mouse Combo",
                    ordered_quantity=30,
                    unit_price_ordered=45.00,
                    line_total_ordered=1350.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-7850",
            po_reference="PO-5600",
            receipt_date="2024-11-28",
            line_items=[
                GRNLineItem(item_code="ITEM-B10", quantity_received=30, accepted_quantity=30),
            ],
            warehouse_note="Full shipment. All items functional.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-1200",
            supplier_name="BrightStar IT Solutions",
            risk_tier="low",
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=100.0,
        ),
        case_history=CaseHistory(),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.approve_for_payment,
            correct_exception_type=ExceptionType.clean_match,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
            ],
            key_findings=[
                "Quantities match (30 ordered, 30 billed, 30 received)",
                "Price matches ($45.00 agreed and billed)",
            ],
        ),
    )


# -- Task 2b: Missing Receipt (GRN shows 0 received) ---------------------
# GRN was filed but zero units accepted. Decision: hold.

def _build_task_2b() -> CaseData:
    return CaseData(
        case_id="CASE-2003",
        task_id=TaskID.task_2b_missing_receipt,
        difficulty=Difficulty.moderate,
        max_steps=10,
        invoice=Invoice(
            invoice_number="INV-2024-0201",
            supplier_name="NorthWind Chemicals",
            supplier_id="SUP-2100",
            invoice_date="2024-12-05",
            po_reference="PO-6300",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-N05",
                    description="Laboratory Grade Ethanol 1L",
                    quantity_billed=200,
                    unit_price_billed=22.00,
                    line_total_billed=4400.00,
                ),
            ],
            subtotal=4400.00,
            tax=352.00,
            total_amount=4752.00,
            note="Shipment dispatched per schedule.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-6300",
            supplier_id="SUP-2100",
            order_date="2024-11-05",
            line_items=[
                POLineItem(
                    item_code="ITEM-N05",
                    description="Laboratory Grade Ethanol 1L",
                    ordered_quantity=200,
                    unit_price_ordered=22.00,
                    line_total_ordered=4400.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-8850",
            po_reference="PO-6300",
            receipt_date="2024-11-30",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-N05",
                    quantity_received=0,
                    accepted_quantity=0,
                    rejected_quantity=0,
                ),
            ],
            warehouse_note="Shipment not yet received. GRN opened pending delivery.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-2100",
            supplier_name="NorthWind Chemicals",
            risk_tier="medium",
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=200.0,
        ),
        case_history=CaseHistory(),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.place_on_hold,
            correct_exception_type=ExceptionType.missing_receipt,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "compare_quantity",
            ],
            key_findings=[
                "GRN shows 0 units received against 200 billed",
                "Shipment has not been delivered or accepted",
                "Cannot pay before goods are received",
            ],
        ),
    )


# -- Task 2c: Over-Receipt (billed more than ordered, received matches ordered) -
# Billed 120 but PO was 100 and GRN accepted 100. Overbilling.

def _build_task_2c() -> CaseData:
    return CaseData(
        case_id="CASE-2004",
        task_id=TaskID.task_2c_over_receipt,
        difficulty=Difficulty.moderate,
        max_steps=10,
        invoice=Invoice(
            invoice_number="INV-2024-0220",
            supplier_name="Pacific Hardware Co",
            supplier_id="SUP-2200",
            invoice_date="2024-12-08",
            po_reference="PO-6400",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-P15",
                    description="Stainless Steel Bolts M10x50 (Box of 100)",
                    quantity_billed=120,
                    unit_price_billed=8.50,
                    line_total_billed=1020.00,
                ),
            ],
            subtotal=1020.00,
            tax=81.60,
            total_amount=1101.60,
            note="Additional 20 boxes included as courtesy stock.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-6400",
            supplier_id="SUP-2200",
            order_date="2024-11-10",
            line_items=[
                POLineItem(
                    item_code="ITEM-P15",
                    description="Stainless Steel Bolts M10x50 (Box of 100)",
                    ordered_quantity=100,
                    unit_price_ordered=8.50,
                    line_total_ordered=850.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-8870",
            po_reference="PO-6400",
            receipt_date="2024-12-03",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-P15",
                    quantity_received=100,
                    accepted_quantity=100,
                ),
            ],
            warehouse_note="Received 100 boxes per PO. No extra stock delivered.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-2200",
            supplier_name="Pacific Hardware Co",
            risk_tier="medium",
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=100.0,
        ),
        case_history=CaseHistory(),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.place_on_hold,
            correct_exception_type=ExceptionType.quantity_mismatch,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "compare_quantity",
            ],
            key_findings=[
                "Invoice bills 120 units but only 100 were ordered and received",
                "Overbilling of 20 units (20% over received)",
                "Variance far exceeds 5% quantity tolerance",
            ],
        ),
    )


# -- Task 3b: Price Within Tolerance (should approve) ---------------------
# Price is 2% above PO, which is within the 5% tolerance. Clean approval.

def _build_task_3b() -> CaseData:
    return CaseData(
        case_id="CASE-3004",
        task_id=TaskID.task_3b_within_tolerance,
        difficulty=Difficulty.moderate,
        max_steps=10,
        invoice=Invoice(
            invoice_number="INV-2024-0330",
            supplier_name="EcoTech Green Supplies",
            supplier_id="SUP-3200",
            invoice_date="2024-12-12",
            po_reference="PO-7200",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-E08",
                    description="Recycled Paper Reams (500 sheets)",
                    quantity_billed=80,
                    unit_price_billed=20.40,
                    line_total_billed=1632.00,
                ),
            ],
            subtotal=1632.00,
            tax=130.56,
            total_amount=1762.56,
            note="Slight price increase due to recycled material costs.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-7200",
            supplier_id="SUP-3200",
            order_date="2024-11-18",
            line_items=[
                POLineItem(
                    item_code="ITEM-E08",
                    description="Recycled Paper Reams (500 sheets)",
                    ordered_quantity=80,
                    unit_price_ordered=20.00,
                    line_total_ordered=1600.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-9170",
            po_reference="PO-7200",
            receipt_date="2024-12-08",
            line_items=[
                GRNLineItem(item_code="ITEM-E08", quantity_received=80, accepted_quantity=80),
            ],
            warehouse_note="All reams received and stored.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-3200",
            supplier_name="EcoTech Green Supplies",
            risk_tier="low",
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=200.0,
        ),
        case_history=CaseHistory(),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.approve_for_payment,
            correct_exception_type=ExceptionType.clean_match,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "compare_price",
            ],
            key_findings=[
                "Price variance of 2% is within 5% tolerance",
                "Quantities match (80 ordered, 80 billed, 80 received)",
                "Acceptable per company policy",
            ],
        ),
    )


# -- Task 3c: Total Amount Mismatch --------------------------------------
# Line-item prices match, but the invoice subtotal is inflated (arithmetic error).

def _build_task_3c() -> CaseData:
    return CaseData(
        case_id="CASE-3005",
        task_id=TaskID.task_3c_total_mismatch,
        difficulty=Difficulty.moderate,
        max_steps=10,
        invoice=Invoice(
            invoice_number="INV-2024-0345",
            supplier_name="Vanguard Medical Supplies",
            supplier_id="SUP-3300",
            invoice_date="2024-12-14",
            po_reference="PO-7300",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-V12",
                    description="Disposable Surgical Masks (Box of 50)",
                    quantity_billed=500,
                    unit_price_billed=6.00,
                    line_total_billed=3000.00,
                ),
            ],
            subtotal=3500.00,
            tax=280.00,
            total_amount=3780.00,
            note="Bulk order -- standard pricing applied.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-7300",
            supplier_id="SUP-3300",
            order_date="2024-11-20",
            line_items=[
                POLineItem(
                    item_code="ITEM-V12",
                    description="Disposable Surgical Masks (Box of 50)",
                    ordered_quantity=500,
                    unit_price_ordered=6.00,
                    line_total_ordered=3000.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-9200",
            po_reference="PO-7300",
            receipt_date="2024-12-10",
            line_items=[
                GRNLineItem(item_code="ITEM-V12", quantity_received=500, accepted_quantity=500),
            ],
            warehouse_note="Full shipment received.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-3300",
            supplier_name="Vanguard Medical Supplies",
            risk_tier="low",
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=200.0,
        ),
        case_history=CaseHistory(),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.escalate_for_supervisor_review,
            correct_exception_type=ExceptionType.total_amount_mismatch,
            acceptable_evidence=[
                "inspect_purchase_order",
                "compare_totals",
            ],
            key_findings=[
                "Invoice subtotal $3,500 does not match line items sum $3,000",
                "Invoice subtotal exceeds PO total by $500 (beyond $200 tolerance)",
                "Possible arithmetic error or hidden charges",
            ],
        ),
    )


# -- Task 4b: Corrected Invoice Trap --------------------------------------
# Invoice claims to be a "corrected version" of a prior invoice, but the
# prior invoice was already paid. Still a duplicate.

def _build_task_4b() -> CaseData:
    return CaseData(
        case_id="CASE-4005",
        task_id=TaskID.task_4b_corrected_invoice_trap,
        difficulty=Difficulty.hard,
        max_steps=12,
        invoice=Invoice(
            invoice_number="INV-2024-0601",
            supplier_name="Atlas Freight Solutions",
            supplier_id="SUP-4300",
            invoice_date="2024-12-20",
            po_reference="PO-8900",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-A20",
                    description="Corrugated Shipping Boxes (Large)",
                    quantity_billed=300,
                    unit_price_billed=4.50,
                    line_total_billed=1350.00,
                ),
            ],
            subtotal=1350.00,
            tax=108.00,
            total_amount=1458.00,
            note="CORRECTED INVOICE -- replaces INV-2024-0600. Please disregard previous version.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-8900",
            supplier_id="SUP-4300",
            order_date="2024-11-22",
            line_items=[
                POLineItem(
                    item_code="ITEM-A20",
                    description="Corrugated Shipping Boxes (Large)",
                    ordered_quantity=300,
                    unit_price_ordered=4.50,
                    line_total_ordered=1350.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-9920",
            po_reference="PO-8900",
            receipt_date="2024-12-15",
            line_items=[
                GRNLineItem(item_code="ITEM-A20", quantity_received=300, accepted_quantity=300),
            ],
            warehouse_note="All boxes received per PO.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-4300",
            supplier_name="Atlas Freight Solutions",
            risk_tier="medium",
            duplicate_risk_count=1,
            preferred_vendor=True,
            escalation_threshold=5000.00,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=200.0,
            duplicate_check_enabled=True,
        ),
        case_history=CaseHistory(
            prior_comments=[
                "INV-2024-0600 was processed and paid on 2024-12-17.",
            ],
            similar_invoice_refs=["INV-2024-0600"],
            processed_invoice_numbers=["INV-2024-0600"],
        ),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.reject_invoice,
            correct_exception_type=ExceptionType.duplicate_invoice,
            acceptable_evidence=[
                "check_for_duplicate_invoice",
                "inspect_vendor_profile",
            ],
            key_findings=[
                "INV-2024-0600 was already processed and paid",
                "Current invoice claims to be a 'correction' but has identical amounts",
                "Supplier has 1 prior duplicate incident",
            ],
        ),
    )


# -- Task 4c: Policy Violation (high-value without authorization) ---------
# Invoice total exceeds high-value threshold. Everything else matches,
# but policy requires escalation for high-value invoices.

def _build_task_4c() -> CaseData:
    return CaseData(
        case_id="CASE-4006",
        task_id=TaskID.task_4c_policy_violation,
        difficulty=Difficulty.hard,
        max_steps=12,
        invoice=Invoice(
            invoice_number="INV-2024-0700",
            supplier_name="TitanWorks Engineering",
            supplier_id="SUP-4400",
            invoice_date="2024-12-22",
            po_reference="PO-9100",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-T30",
                    description="CNC Machined Aluminum Housing Unit",
                    quantity_billed=100,
                    unit_price_billed=520.00,
                    line_total_billed=52000.00,
                ),
            ],
            subtotal=52000.00,
            tax=4160.00,
            total_amount=56160.00,
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-9100",
            supplier_id="SUP-4400",
            order_date="2024-12-01",
            line_items=[
                POLineItem(
                    item_code="ITEM-T30",
                    description="CNC Machined Aluminum Housing Unit",
                    ordered_quantity=100,
                    unit_price_ordered=520.00,
                    line_total_ordered=52000.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-9950",
            po_reference="PO-9100",
            receipt_date="2024-12-18",
            line_items=[
                GRNLineItem(item_code="ITEM-T30", quantity_received=100, accepted_quantity=100),
            ],
            warehouse_note="All units received. Quality inspection passed.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-4400",
            supplier_name="TitanWorks Engineering",
            risk_tier="medium",
            preferred_vendor=True,
            escalation_threshold=40000.00,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=500.0,
            high_value_threshold=50000.0,
        ),
        case_history=CaseHistory(),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.escalate_for_supervisor_review,
            correct_exception_type=ExceptionType.policy_violation,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_policy_rules",
                "inspect_vendor_profile",
            ],
            key_findings=[
                "Invoice total $56,160 exceeds high-value threshold of $50,000",
                "All quantities and prices match, but policy requires supervisor review",
                "Invoice also exceeds vendor escalation threshold of $40,000",
            ],
        ),
    )


# ===========================================================================
# GENUINELY HARD TASKS
# ===========================================================================


# -- Task 5: Mixed Discrepancy (price over tolerance + partial receipt) ---
# Difficulty: hard | Decision: escalate_for_supervisor_review
# Exception: mixed_discrepancy
#
# This case has TWO simultaneous issues:
#   1. Price variance: $55 billed vs $50 PO (10%, exceeds 5% tolerance)
#   2. Partial receipt: billed 200, only 150 received
# Both "hold" and "escalate" seem reasonable. Per policy, price variance
# exceeding tolerance triggers escalation, which takes priority over hold.
# The agent must read the policy rules and recognize escalation outranks hold.

def _build_task_5() -> CaseData:
    return CaseData(
        case_id="CASE-5001",
        task_id=TaskID.task_5_mixed_discrepancy,
        difficulty=Difficulty.hard,
        max_steps=12,
        invoice=Invoice(
            invoice_number="INV-2024-0850",
            supplier_name="GlobalParts Manufacturing",
            supplier_id="SUP-5100",
            invoice_date="2024-12-20",
            po_reference="PO-9500",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-G40",
                    description="Precision Titanium Fasteners (Box of 25)",
                    quantity_billed=200,
                    unit_price_billed=55.00,
                    line_total_billed=11000.00,
                ),
            ],
            subtotal=11000.00,
            tax=880.00,
            total_amount=11880.00,
            note="Price reflects updated material costs. Partial shipment billed in full per contract terms.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-9500",
            supplier_id="SUP-5100",
            order_date="2024-11-25",
            line_items=[
                POLineItem(
                    item_code="ITEM-G40",
                    description="Precision Titanium Fasteners (Box of 25)",
                    ordered_quantity=200,
                    unit_price_ordered=50.00,
                    line_total_ordered=10000.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-10200",
            po_reference="PO-9500",
            receipt_date="2024-12-15",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-G40",
                    quantity_received=150,
                    accepted_quantity=150,
                    rejected_quantity=0,
                ),
            ],
            warehouse_note="Partial shipment. 50 boxes backordered, ETA 2 weeks.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-5100",
            supplier_name="GlobalParts Manufacturing",
            risk_tier="medium",
            preferred_vendor=True,
            escalation_threshold=8000.00,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=300.0,
            high_value_threshold=50000.0,
        ),
        case_history=CaseHistory(
            prior_comments=[
                "Supplier has a history of price adjustments on raw material orders.",
            ],
        ),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.escalate_for_supervisor_review,
            correct_exception_type=ExceptionType.mixed_discrepancy,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "compare_quantity",
                "compare_price",
                "inspect_policy_rules",
            ],
            key_findings=[
                "Price variance: $55 billed vs $50 PO (10%, exceeds 5% tolerance)",
                "Quantity discrepancy: billed 200 but only 150 received (25% short)",
                "Both price escalation and quantity hold conditions triggered",
                "Per policy, price variance exceeding tolerance requires escalation",
                "Escalation takes priority over hold when both apply",
            ],
        ),
    )


# -- Task 6: False Positive Duplicate (legitimate second order) -----------
# Difficulty: hard | Decision: approve_for_payment
# Exception: clean_match
#
# This case is designed to trap agents that rely on superficial pattern
# matching. The invoice is from the SAME supplier, for the SAME item,
# with a SIMILAR amount -- but references a DIFFERENT PO number. The case
# history has a processed invoice for PO-9600, but this invoice is for
# PO-9700 (a separate legitimate order). The vendor note mentioning
# "same as last month" is a red herring.
#
# The agent must carefully check PO references rather than assuming
# duplicate based on supplier + amount similarity.

def _build_task_6() -> CaseData:
    return CaseData(
        case_id="CASE-6001",
        task_id=TaskID.task_6_false_positive_duplicate,
        difficulty=Difficulty.hard,
        max_steps=12,
        invoice=Invoice(
            invoice_number="INV-2024-0920",
            supplier_name="Metro Cleaning Services",
            supplier_id="SUP-6100",
            invoice_date="2024-12-28",
            po_reference="PO-9700",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-M15",
                    description="Monthly Office Cleaning Service - January",
                    quantity_billed=1,
                    unit_price_billed=4500.00,
                    line_total_billed=4500.00,
                ),
            ],
            subtotal=4500.00,
            tax=360.00,
            total_amount=4860.00,
            note="Monthly service invoice -- same as last month's order.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-9700",
            supplier_id="SUP-6100",
            order_date="2024-12-15",
            line_items=[
                POLineItem(
                    item_code="ITEM-M15",
                    description="Monthly Office Cleaning Service - January",
                    ordered_quantity=1,
                    unit_price_ordered=4500.00,
                    line_total_ordered=4500.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-10500",
            po_reference="PO-9700",
            receipt_date="2024-12-26",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-M15",
                    quantity_received=1,
                    accepted_quantity=1,
                ),
            ],
            warehouse_note="Service confirmed completed for January cycle.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-6100",
            supplier_name="Metro Cleaning Services",
            risk_tier="low",
            duplicate_risk_count=0,
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=200.0,
            duplicate_check_enabled=True,
        ),
        case_history=CaseHistory(
            prior_comments=[
                "Monthly recurring service contract. New PO issued each month.",
            ],
            processed_invoice_numbers=[
                "INV-2024-0880",
            ],
            similar_invoice_refs=[],
        ),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.approve_for_payment,
            correct_exception_type=ExceptionType.clean_match,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "check_for_duplicate_invoice",
            ],
            key_findings=[
                "Invoice references PO-9700, which is a separate order from prior PO-9600",
                "Prior invoice INV-2024-0880 was for a different PO (different month)",
                "Quantities and prices match PO exactly",
                "No actual duplicate -- this is a legitimate recurring service invoice",
                "Vendor has 0 duplicate risk incidents",
            ],
        ),
    )


# -- Task 7: Retroactive Price Adjustment -----------------------------------
# Difficulty: hard | Decision: escalate_for_supervisor_review | Exception: price_mismatch
# Vendor had a contract price change effective 2024-11-01, but the PO was issued
# at the old price on 2024-10-20. The invoice uses the NEW (higher) price.
# Agent must notice the temporal mismatch: PO predates the price change, so the
# PO price is the agreed-upon price. The invoice price exceeds tolerance.
# Tests temporal reasoning and policy awareness.


def _build_task_7() -> CaseData:
    return CaseData(
        case_id="CASE-7001",
        task_id=TaskID.task_7_retroactive_price,
        difficulty=Difficulty.hard,
        max_steps=12,
        invoice=Invoice(
            invoice_number="INV-2024-1150",
            supplier_name="Precision Parts Ltd",
            supplier_id="SUP-7100",
            invoice_date="2024-11-10",
            po_reference="PO-7500",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-PP01",
                    description="CNC Bearing Assembly Type-R",
                    quantity_billed=200,
                    unit_price_billed=47.50,
                    line_total_billed=9500.00,
                ),
                InvoiceLineItem(
                    item_code="ITEM-PP02",
                    description="Hydraulic Seal Kit Grade-A",
                    quantity_billed=500,
                    unit_price_billed=12.80,
                    line_total_billed=6400.00,
                ),
            ],
            subtotal=15900.00,
            tax=1272.00,
            total_amount=17172.00,
            note="Prices reflect updated catalog effective 2024-11-01.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-7500",
            supplier_id="SUP-7100",
            order_date="2024-10-20",
            line_items=[
                POLineItem(
                    item_code="ITEM-PP01",
                    description="CNC Bearing Assembly Type-R",
                    ordered_quantity=200,
                    unit_price_ordered=42.00,
                    line_total_ordered=8400.00,
                ),
                POLineItem(
                    item_code="ITEM-PP02",
                    description="Hydraulic Seal Kit Grade-A",
                    ordered_quantity=500,
                    unit_price_ordered=11.50,
                    line_total_ordered=5750.00,
                ),
            ],
            payment_terms="Net 45",
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-12500",
            po_reference="PO-7500",
            receipt_date="2024-11-05",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-PP01",
                    quantity_received=200,
                    accepted_quantity=200,
                ),
                GRNLineItem(
                    item_code="ITEM-PP02",
                    quantity_received=500,
                    accepted_quantity=500,
                ),
            ],
            warehouse_note="All items received in good condition. Full order.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-7100",
            supplier_name="Precision Parts Ltd",
            risk_tier="medium",
            duplicate_risk_count=0,
            preferred_vendor=True,
            escalation_threshold=15000.00,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=500.0,
            duplicate_check_enabled=True,
            high_value_threshold=50000.0,
        ),
        case_history=CaseHistory(
            prior_comments=[
                "Vendor announced price increase effective 2024-11-01.",
                "PO-7500 was placed on 2024-10-20 at the old catalog prices.",
                "Contract terms: PO price governs unless amended before shipment.",
            ],
        ),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.escalate_for_supervisor_review,
            correct_exception_type=ExceptionType.price_mismatch,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "compare_price",
                "inspect_policy_rules",
                "inspect_vendor_profile",
            ],
            key_findings=[
                "ITEM-PP01 billed at $47.50 vs PO price $42.00 (13.1% variance)",
                "ITEM-PP02 billed at $12.80 vs PO price $11.50 (11.3% variance)",
                "Both exceed 5% price tolerance",
                "PO was issued 2024-10-20, before price change effective 2024-11-01",
                "Per contract terms, PO price governs unless PO is amended",
                "Invoice total $17,172 exceeds vendor escalation threshold $15,000",
            ],
        ),
    )


# -- Task 8: Adversarial Split-Invoice Pattern --------------------------------
# Difficulty: hard | Decision: escalate_for_supervisor_review | Exception: policy_violation
# Supplier splits a large order into multiple smaller invoices to stay below
# the auto-approval threshold ($50,000). Each individual invoice looks clean,
# but case history reveals a pattern of split invoicing from this vendor.
# Agent must check vendor profile (high duplicate risk count) and case history
# to detect the pattern. Tests cross-case pattern recognition.


def _build_task_8() -> CaseData:
    return CaseData(
        case_id="CASE-8001",
        task_id=TaskID.task_8_split_invoice_pattern,
        difficulty=Difficulty.hard,
        max_steps=12,
        invoice=Invoice(
            invoice_number="INV-2024-2210",
            supplier_name="Global Tech Supplies",
            supplier_id="SUP-8200",
            invoice_date="2024-12-01",
            po_reference="PO-8800",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-GT10",
                    description="Enterprise Server Rack Unit 42U",
                    quantity_billed=3,
                    unit_price_billed=14500.00,
                    line_total_billed=43500.00,
                ),
            ],
            subtotal=43500.00,
            tax=3480.00,
            total_amount=46980.00,
            note="Shipment 3 of 3. Final batch for data center buildout.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-8800",
            supplier_id="SUP-8200",
            order_date="2024-11-15",
            line_items=[
                POLineItem(
                    item_code="ITEM-GT10",
                    description="Enterprise Server Rack Unit 42U",
                    ordered_quantity=3,
                    unit_price_ordered=14500.00,
                    line_total_ordered=43500.00,
                ),
            ],
            payment_terms="Net 30",
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-15200",
            po_reference="PO-8800",
            receipt_date="2024-11-28",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-GT10",
                    quantity_received=3,
                    accepted_quantity=3,
                ),
            ],
            warehouse_note="Final batch received. All 9 rack units now in inventory.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-8200",
            supplier_name="Global Tech Supplies",
            risk_tier="high",
            duplicate_risk_count=4,
            preferred_vendor=False,
            escalation_threshold=40000.00,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=500.0,
            duplicate_check_enabled=True,
            high_value_threshold=50000.00,
            mandatory_escalation_above=100000.00,
        ),
        case_history=CaseHistory(
            prior_comments=[
                "ALERT: Vendor SUP-8200 has submitted 3 invoices this month "
                "for similar items across 3 separate POs (PO-8600, PO-8700, PO-8800).",
                "Each invoice is just under the $50,000 auto-approval threshold.",
                "Combined value: $46,200 + $47,800 + $46,980 = $140,980.",
                "Finance team flagged potential invoice-splitting pattern.",
                "Vendor is non-preferred with 4 prior risk incidents.",
            ],
            similar_invoice_refs=["INV-2024-2180", "INV-2024-2195"],
            processed_invoice_numbers=["INV-2024-2180", "INV-2024-2195"],
        ),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.escalate_for_supervisor_review,
            correct_exception_type=ExceptionType.policy_violation,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "inspect_vendor_profile",
                "inspect_policy_rules",
                "check_for_duplicate_invoice",
            ],
            key_findings=[
                "Invoice $46,980 is just under auto-approval threshold of $50,000",
                "3 similar invoices from same vendor total $140,980",
                "Vendor is high-risk tier with 4 prior risk incidents",
                "Vendor is non-preferred",
                "Case history explicitly flags split-invoice pattern concern",
                "Combined value exceeds mandatory escalation threshold of $100,000",
                "Individual prices and quantities match PO -- no line-level discrepancy",
            ],
        ),
    )


# -- Task 9: Clean Invoice from High-Risk Vendor ----------------------------
# Difficulty: hard | Decision: approve_for_payment | Exception: clean_match
# Every document matches perfectly. But the vendor is HIGH RISK with 5 prior
# incidents and is non-preferred. The trap: agents escalate or reject based
# on vendor risk alone. Per policy, risk tier affects escalation thresholds
# for discrepancies, not clean invoices. No discrepancy = approve.


def _build_task_9() -> CaseData:
    return CaseData(
        case_id="CASE-9001",
        task_id=TaskID.task_9_clean_from_risky_vendor,
        difficulty=Difficulty.hard,
        max_steps=12,
        invoice=Invoice(
            invoice_number="INV-2024-3300",
            supplier_name="Delta Industrial Components",
            supplier_id="SUP-9300",
            invoice_date="2024-12-10",
            po_reference="PO-9200",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-DC01",
                    description="Steel Flanged Coupling 6-inch",
                    quantity_billed=50,
                    unit_price_billed=85.00,
                    line_total_billed=4250.00,
                ),
                InvoiceLineItem(
                    item_code="ITEM-DC02",
                    description="Gasket Kit Industrial Grade",
                    quantity_billed=200,
                    unit_price_billed=12.50,
                    line_total_billed=2500.00,
                ),
            ],
            subtotal=6750.00,
            tax=540.00,
            total_amount=7290.00,
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-9200",
            supplier_id="SUP-9300",
            order_date="2024-11-25",
            line_items=[
                POLineItem(
                    item_code="ITEM-DC01",
                    description="Steel Flanged Coupling 6-inch",
                    ordered_quantity=50,
                    unit_price_ordered=85.00,
                    line_total_ordered=4250.00,
                ),
                POLineItem(
                    item_code="ITEM-DC02",
                    description="Gasket Kit Industrial Grade",
                    ordered_quantity=200,
                    unit_price_ordered=12.50,
                    line_total_ordered=2500.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-16000",
            po_reference="PO-9200",
            receipt_date="2024-12-05",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-DC01",
                    quantity_received=50,
                    accepted_quantity=50,
                ),
                GRNLineItem(
                    item_code="ITEM-DC02",
                    quantity_received=200,
                    accepted_quantity=200,
                ),
            ],
            warehouse_note="Full order received. Quality inspection passed.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-9300",
            supplier_name="Delta Industrial Components",
            risk_tier="high",
            duplicate_risk_count=5,
            preferred_vendor=False,
            escalation_threshold=5000.00,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=200.0,
            duplicate_check_enabled=True,
        ),
        case_history=CaseHistory(
            prior_comments=[
                "Vendor under enhanced monitoring due to past billing errors.",
                "Last 3 invoices from this vendor were all clean and processed normally.",
                "Risk tier remains 'high' pending annual vendor review in Q1 2025.",
            ],
        ),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.approve_for_payment,
            correct_exception_type=ExceptionType.clean_match,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "compare_quantity",
                "compare_price",
                "inspect_vendor_profile",
                "inspect_policy_rules",
            ],
            key_findings=[
                "All quantities match exactly: 50 couplings and 200 gasket kits",
                "All prices match PO exactly: $85.00 and $12.50",
                "Vendor is high-risk but no actual discrepancy exists",
                "Risk tier affects escalation thresholds, not clean invoices",
                "Last 3 invoices from this vendor were processed normally",
                "No policy rule mandates rejection of clean invoices from high-risk vendors",
            ],
        ),
    )


# -- Task 10: Rounding Error False Alarm ------------------------------------
# Difficulty: hard | Decision: approve_for_payment | Exception: clean_match
# Invoice total is $0.01 off from calculated sum of line items due to
# per-line rounding. All line items match PO exactly. The trivial rounding
# difference is well within any tolerance. Trap: compare_totals reports a
# "mismatch" finding and agents escalate over one cent.


def _build_task_10() -> CaseData:
    return CaseData(
        case_id="CASE-10001",
        task_id=TaskID.task_10_rounding_false_alarm,
        difficulty=Difficulty.hard,
        max_steps=12,
        invoice=Invoice(
            invoice_number="INV-2024-4410",
            supplier_name="Kensington Paper & Print",
            supplier_id="SUP-10400",
            invoice_date="2024-12-15",
            po_reference="PO-10100",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-KP01",
                    description="A4 Premium Copy Paper (case of 10 reams)",
                    quantity_billed=33,
                    unit_price_billed=42.99,
                    line_total_billed=1418.67,
                ),
                InvoiceLineItem(
                    item_code="ITEM-KP02",
                    description="Color Laser Toner Cartridge Black",
                    quantity_billed=7,
                    unit_price_billed=189.99,
                    line_total_billed=1329.93,
                ),
                InvoiceLineItem(
                    item_code="ITEM-KP03",
                    description="Binding Covers Glossy A4 (pack of 100)",
                    quantity_billed=15,
                    unit_price_billed=28.33,
                    line_total_billed=424.95,
                ),
            ],
            subtotal=3173.55,
            tax=253.88,
            total_amount=3427.43,
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-10100",
            supplier_id="SUP-10400",
            order_date="2024-12-01",
            line_items=[
                POLineItem(
                    item_code="ITEM-KP01",
                    description="A4 Premium Copy Paper (case of 10 reams)",
                    ordered_quantity=33,
                    unit_price_ordered=42.99,
                    line_total_ordered=1418.67,
                ),
                POLineItem(
                    item_code="ITEM-KP02",
                    description="Color Laser Toner Cartridge Black",
                    ordered_quantity=7,
                    unit_price_ordered=189.99,
                    line_total_ordered=1329.93,
                ),
                POLineItem(
                    item_code="ITEM-KP03",
                    description="Binding Covers Glossy A4 (pack of 100)",
                    ordered_quantity=15,
                    unit_price_ordered=28.33,
                    line_total_ordered=424.95,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-17500",
            po_reference="PO-10100",
            receipt_date="2024-12-10",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-KP01",
                    quantity_received=33,
                    accepted_quantity=33,
                ),
                GRNLineItem(
                    item_code="ITEM-KP02",
                    quantity_received=7,
                    accepted_quantity=7,
                ),
                GRNLineItem(
                    item_code="ITEM-KP03",
                    quantity_received=15,
                    accepted_quantity=15,
                ),
            ],
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-10400",
            supplier_name="Kensington Paper & Print",
            risk_tier="low",
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=100.0,
            duplicate_check_enabled=True,
        ),
        case_history=CaseHistory(),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.approve_for_payment,
            correct_exception_type=ExceptionType.clean_match,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "compare_quantity",
                "compare_price",
                "compare_totals",
                "inspect_policy_rules",
            ],
            key_findings=[
                "All quantities match exactly",
                "All unit prices match PO exactly",
                "Subtotal rounding difference of $0.01 is within tolerance",
                "Total tolerance is $100.00 -- a $0.01 difference is negligible",
                "Rounding is a normal artifact of multi-line calculation",
                "Preferred vendor with low risk tier",
            ],
        ),
    )


# -- Task 11: Authorized Overship -------------------------------------------
# Difficulty: hard | Decision: approve_for_payment | Exception: clean_match
# GRN shows 110 units received vs 100 ordered. Invoice bills for 110.
# Case history contains explicit authorization for up to 10% overship.
# Trap: agents see quantity mismatch and hold. But the overship was
# pre-authorized, making this a clean match per the authorization.


def _build_task_11() -> CaseData:
    return CaseData(
        case_id="CASE-11001",
        task_id=TaskID.task_11_authorized_overship,
        difficulty=Difficulty.hard,
        max_steps=12,
        invoice=Invoice(
            invoice_number="INV-2024-5520",
            supplier_name="Pacific Coast Fasteners",
            supplier_id="SUP-11500",
            invoice_date="2024-12-18",
            po_reference="PO-11300",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-PF01",
                    description="M8 Hex Bolt Grade 8.8 Zinc Plated (box of 100)",
                    quantity_billed=110,
                    unit_price_billed=24.50,
                    line_total_billed=2695.00,
                ),
            ],
            subtotal=2695.00,
            tax=215.60,
            total_amount=2910.60,
            note="Quantity includes authorized 10% overship per PO amendment.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-11300",
            supplier_id="SUP-11500",
            order_date="2024-12-01",
            line_items=[
                POLineItem(
                    item_code="ITEM-PF01",
                    description="M8 Hex Bolt Grade 8.8 Zinc Plated (box of 100)",
                    ordered_quantity=100,
                    unit_price_ordered=24.50,
                    line_total_ordered=2450.00,
                ),
            ],
            payment_terms="Net 30",
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-18800",
            po_reference="PO-11300",
            receipt_date="2024-12-12",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-PF01",
                    quantity_received=110,
                    accepted_quantity=110,
                ),
            ],
            warehouse_note="110 boxes received. Overship authorized per buyer memo dated 2024-12-02.",
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-11500",
            supplier_name="Pacific Coast Fasteners",
            risk_tier="low",
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=500.0,
            duplicate_check_enabled=True,
        ),
        case_history=CaseHistory(
            prior_comments=[
                "PO-11300 Amendment 1 (2024-12-02): Authorized up to 10% overship "
                "at the same unit price to ensure inventory buffer for Q1.",
                "Buyer confirmed acceptance of up to 110 boxes at $24.50/box.",
                "Warehouse confirmed receipt of full 110 boxes in good condition.",
            ],
        ),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.approve_for_payment,
            correct_exception_type=ExceptionType.clean_match,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "compare_quantity",
                "inspect_policy_rules",
            ],
            key_findings=[
                "Billed 110 vs ordered 100 -- 10% overship",
                "PO Amendment 1 explicitly authorized up to 10% overship",
                "Buyer confirmed acceptance of 110 units at $24.50",
                "GRN confirms all 110 accepted in good condition",
                "Unit price matches PO exactly",
                "Overship is within the authorized range",
            ],
        ),
    )


# -- Task 12: Corrected Invoice Resubmission --------------------------------
# Difficulty: hard | Decision: approve_for_payment | Exception: clean_match
# Invoice number INV-2024-0500-R1 looks like a duplicate of INV-2024-0500.
# Case history shows the original was rejected for a $500 overcharge, and
# this is the corrected resubmission at the correct PO price. All documents
# now match. Trap: duplicate check flags the similar invoice number, and
# agents reject as duplicate without reading the correction context.


def _build_task_12() -> CaseData:
    return CaseData(
        case_id="CASE-12001",
        task_id=TaskID.task_12_corrected_resubmission,
        difficulty=Difficulty.hard,
        max_steps=12,
        invoice=Invoice(
            invoice_number="INV-2024-0500-R1",
            supplier_name="Westfield Electronics",
            supplier_id="SUP-12600",
            invoice_date="2024-12-20",
            po_reference="PO-12400",
            line_items=[
                InvoiceLineItem(
                    item_code="ITEM-WE01",
                    description="Industrial Ethernet Switch 24-Port PoE+",
                    quantity_billed=5,
                    unit_price_billed=1250.00,
                    line_total_billed=6250.00,
                ),
                InvoiceLineItem(
                    item_code="ITEM-WE02",
                    description="SFP+ 10G Transceiver Module",
                    quantity_billed=20,
                    unit_price_billed=85.00,
                    line_total_billed=1700.00,
                ),
            ],
            subtotal=7950.00,
            tax=636.00,
            total_amount=8586.00,
            note="Corrected invoice. Replaces INV-2024-0500 which was rejected for pricing error.",
        ),
        purchase_order=PurchaseOrder(
            po_number="PO-12400",
            supplier_id="SUP-12600",
            order_date="2024-12-01",
            line_items=[
                POLineItem(
                    item_code="ITEM-WE01",
                    description="Industrial Ethernet Switch 24-Port PoE+",
                    ordered_quantity=5,
                    unit_price_ordered=1250.00,
                    line_total_ordered=6250.00,
                ),
                POLineItem(
                    item_code="ITEM-WE02",
                    description="SFP+ 10G Transceiver Module",
                    ordered_quantity=20,
                    unit_price_ordered=85.00,
                    line_total_ordered=1700.00,
                ),
            ],
        ),
        goods_receipt_note=GoodsReceiptNote(
            grn_number="GRN-20100",
            po_reference="PO-12400",
            receipt_date="2024-12-10",
            line_items=[
                GRNLineItem(
                    item_code="ITEM-WE01",
                    quantity_received=5,
                    accepted_quantity=5,
                ),
                GRNLineItem(
                    item_code="ITEM-WE02",
                    quantity_received=20,
                    accepted_quantity=20,
                ),
            ],
        ),
        vendor_profile=VendorProfile(
            supplier_id="SUP-12600",
            supplier_name="Westfield Electronics",
            risk_tier="medium",
            duplicate_risk_count=1,
            preferred_vendor=True,
        ),
        company_policy=CompanyPolicy(
            quantity_tolerance_pct=5.0,
            price_tolerance_pct=5.0,
            total_tolerance_amt=200.0,
            duplicate_check_enabled=True,
        ),
        case_history=CaseHistory(
            prior_comments=[
                "INV-2024-0500 was rejected on 2024-12-15: switches billed at $1,350 "
                "instead of PO price $1,250. Vendor acknowledged error.",
                "Vendor issued corrected invoice INV-2024-0500-R1 with correct pricing.",
                "AP team confirmed: process INV-2024-0500-R1 as the replacement invoice.",
            ],
            processed_invoice_numbers=[],
            similar_invoice_refs=["INV-2024-0500"],
        ),
        ground_truth=GroundTruth(
            correct_decision=DecisionType.approve_for_payment,
            correct_exception_type=ExceptionType.clean_match,
            acceptable_evidence=[
                "inspect_purchase_order",
                "inspect_goods_receipt_note",
                "compare_price",
                "check_for_duplicate_invoice",
                "inspect_policy_rules",
            ],
            key_findings=[
                "INV-2024-0500-R1 is the corrected version of rejected INV-2024-0500",
                "Original invoice was rejected for $100/unit price overcharge on switches",
                "Corrected invoice has the correct PO price of $1,250 per switch",
                "All quantities and prices now match PO exactly",
                "AP team explicitly approved processing the replacement invoice",
                "Not a duplicate -- it is a correction of a rejected invoice",
            ],
        ),
    )