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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
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
---

## πŸ“‘ Table of Contents

### Part A β€” General & Authentication
- [0. General Information](#0-general-information)
- [1. Authentication](#1-authentication)

### Part B β€” User (Customer) Side
- [2. User Profile](#2-user-profile)
- [3. Home (User)](#3-home-user)
- [4. Service Categories](#4-service-categories)
- [5. Nearby Workers (Tukang Dekat)](#5-nearby-workers-tukang-dekat)
- [6. Worker Detail (Detail Tukang)](#6-worker-detail-detail-tukang)
- [7. Orders β€” User Side](#7-orders--user-side)
- [8. Tracking β€” User Side](#8-tracking--user-side)
- [9. Purchase Tracking β€” User Side](#9-purchase-tracking--user-side)
- [10. Chat β€” User Side](#10-chat--user-side)
- [11. Rating & Review β€” User Side](#11-rating--review--user-side)
- [12. Invoice & Payment β€” User Side](#12-invoice--payment--user-side)
- [13. Knowledge / FAQ / Guide](#13-knowledge--faq--guide)
- [14. Notifications](#14-notifications)

### Part C β€” Worker (Tukang) Side
- [15. Worker Profile & Verification](#15-worker-profile--verification)
- [16. Home (Worker)](#16-home-worker)
- [17. Incoming Orders β€” Worker Side](#17-incoming-orders--worker-side)
- [18. Order Management β€” Worker Side](#18-order-management--worker-side)
- [19. Purchase Management β€” Worker Side (AI-Assisted)](#19-purchase-management--worker-side-ai-assisted)
- [20. Chat β€” Worker Side](#20-chat--worker-side)
- [21. Rating β€” Worker Side (Rate Customer)](#21-rating--worker-side-rate-customer)
- [22. History & Statistics β€” Worker Side](#22-history--statistics--worker-side)
- [23. Wallet β€” Worker Side](#23-wallet--worker-side)
- [24. Worker Location Updates](#24-worker-location-updates)

### Part D β€” Shared
- [25. WebSocket Events](#25-websocket-events)
- [26. Enums & Shared Schemas](#26-enums--shared-schemas)
- [27. Error Responses](#27-error-responses)
- [28. Endpoint Summary Table](#28-endpoint-summary-table)

---

## 0. General Information

### 0.1 Base URL

| Environment | URL |
|---|---|
| Production | `https://api.situkang.id/v1` |
| Staging | `https://staging-api.situkang.id/v1` |
| Development | `http://localhost:3000/v1` |

### 0.2 Content Types

| Content-Type | Usage |
|---|---|
| `application/json` | Default request/response body |
| `multipart/form-data` | File upload (avatar, photos, receipts) |

### 0.3 Authentication β€” RBAC via JWT

SiTukang uses a **single backend** for both User and Worker. Role differentiation is handled via the `role` field embedded in the JWT access token. Middleware checks this field to authorize or deny access to role-specific endpoints.

```yaml
securitySchemes:
  BearerAuth:
    type: http
    scheme: bearer
    bearerFormat: JWT
    description: |
      JWT token containing user role.
      Include in header: Authorization: Bearer <token>
```

**JWT Payload Structure:**

```json
{
  "sub": "550e8400-e29b-41d4-a716-446655440000",
  "role": "user",
  "email": "budi@email.com",
  "full_name": "Budi Santoso",
  "iat": 1698230400,
  "exp": 1698234000,
  "jti": "unique-token-id"
}
```

**Middleware RBAC Flow:**

```
Request
  β†’ Extract Bearer token from Authorization header
  β†’ Verify JWT signature & expiry
  β†’ Decode payload β†’ extract `role`
  β†’ Match role against endpoint requirement:
      β”œβ”€β”€ role == "user"   β†’ User endpoints βœ… | Worker endpoints ❌
      β”œβ”€β”€ role == "worker" β†’ Worker endpoints βœ… | User endpoints ❌
      β”œβ”€β”€ role == "admin"  β†’ All endpoints βœ…
      └── Invalid/expired  β†’ 401 Unauthorized
```

### 0.4 Rate Limiting

All responses include rate limiting headers:

```
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1698230400
```

### 0.5 Pagination Convention

All list endpoints use consistent pagination:

```json
{
  "meta": {
    "current_page": 1,
    "per_page": 10,
    "total": 150,
    "total_pages": 15
  }
}
```

### 0.6 Common HTTP Status Codes

| Code | Usage |
|---|---|
| `200` | Success (GET, PUT, PATCH) |
| `201` | Resource created (POST) |
| `204` | Success, no content (DELETE) |
| `400` | Bad Request β€” invalid parameters |
| `401` | Unauthorized β€” invalid/expired token |
| `403` | Forbidden β€” role mismatch |
| `404` | Not Found |
| `409` | Conflict β€” duplicate resource |
| `422` | Unprocessable Entity β€” business validation failed |
| `429` | Rate Limited |
| `500` | Internal Server Error |

---

## 1. Authentication

> Auth endpoints are **role-agnostic** β€” both user and worker use the same endpoints. The `role` is set during registration and embedded in the JWT.

---

### 1.1 `POST /auth/register`

> Register a new account (user or worker).

**Request Body:**

```json
{
  "full_name": "Budi Santoso",
  "email": "budi@email.com",
  "phone": "+6281234567890",
  "password": "SecureP@ss123",
  "password_confirmation": "SecureP@ss123",
  "role": "user",
  "latitude": -7.257500,
  "longitude": 112.752100,
  "address": "Jl. Merdeka No. 12, Surabaya"
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `full_name` | string | βœ… | Full name (max 255 chars) |
| `email` | string | βœ… | Unique email address |
| `phone` | string | βœ… | Phone number with country code |
| `password` | string | βœ… | Min 8 chars, must include uppercase, lowercase, number |
| `password_confirmation` | string | βœ… | Must match password |
| `role` | enum | βœ… | `user` or `worker` |
| `latitude` | number | ❌ | Current latitude |
| `longitude` | number | ❌ | Current longitude |
| `address` | string | ❌ | Full address |

**Response `201 Created`:**

```json
{
  "status": "success",
  "message": "Registrasi berhasil",
  "data": {
    "user_id": "550e8400-e29b-41d4-a716-446655440000",
    "full_name": "Budi Santoso",
    "email": "budi@email.com",
    "phone": "+6281234567890",
    "role": "user",
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refresh_token": "dGhpcyBpcyBhIHJlZnJlc2ggdG9rZW4...",
    "token_type": "Bearer",
    "expires_in": 3600
  }
}
```

**Error `409 Conflict`:**

```json
{
  "status": "error",
  "message": "Email sudah terdaftar",
  "error_code": "EMAIL_ALREADY_EXISTS"
}
```

---

### 1.2 `POST /auth/login`

> Login for any role.

**Request Body:**

```json
{
  "email": "budi@email.com",
  "password": "SecureP@ss123"
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "user_id": "550e8400-e29b-41d4-a716-446655440000",
    "full_name": "Budi Santoso",
    "role": "user",
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refresh_token": "dGhpcyBpcyBhIHJlZnJlc2ggdG9rZW4...",
    "token_type": "Bearer",
    "expires_in": 3600
  }
}
```

**Error `401 Unauthorized`:**

```json
{
  "status": "error",
  "message": "Email atau password salah",
  "error_code": "INVALID_CREDENTIALS"
}
```

---

### 1.3 `POST /auth/refresh`

> Refresh access token using refresh token. Old refresh token is invalidated (rotation).

**Request Body:**

```json
{
  "refresh_token": "dGhpcyBpcyBhIHJlZnJlc2ggdG9rZW4..."
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refresh_token": "bmV3IHJlZnJlc2ggdG9rZW4...",
    "token_type": "Bearer",
    "expires_in": 3600
  }
}
```

---

### 1.4 `POST /auth/logout`

> Logout and invalidate refresh token.

πŸ”’ **Auth Required** β€” Any role

**Request Headers:**

```
Authorization: Bearer <access_token>
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Berhasil logout"
}
```

---

### 1.5 `POST /auth/forgot-password`

> Send password reset link to email.

**Request Body:**

```json
{
  "email": "budi@email.com"
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Link reset password telah dikirim ke email Anda"
}
```

---

### 1.6 `POST /auth/reset-password`

> Reset password using token from email.

**Request Body:**

```json
{
  "token": "reset-token-from-email",
  "password": "NewSecureP@ss456",
  "password_confirmation": "NewSecureP@ss456"
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Password berhasil direset"
}
```

---

## 2. User Profile

> Endpoints for user profile management. Used in Profile tab and Home screen greeting.

---

### 2.1 `GET /users/me`

> Get current authenticated user's profile.

πŸ”’ **Auth Required** β€” Role: `user`, `worker`, `admin`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "user_id": "550e8400-e29b-41d4-a716-446655440000",
    "full_name": "Budi Santoso",
    "email": "budi@email.com",
    "phone": "+6281234567890",
    "role": "user",
    "avatar_url": "https://cdn.handydirect.id/avatars/budi_001.jpg",
    "address": "Jl. Merdeka No. 12, Surabaya",
    "latitude": -7.257500,
    "longitude": 112.752100,
    "is_active": true,
    "email_verified_at": "2023-01-15T10:00:00Z",
    "phone_verified_at": "2023-01-15T10:05:00Z",
    "last_login_at": "2026-05-30T08:00:00Z",
    "created_at": "2023-01-15T10:00:00Z",
    "active_orders_count": 1
  }
}
```

---

### 2.2 `PUT /users/me`

> Update user profile info.

πŸ”’ **Auth Required** β€” Role: `user`, `worker`, `admin`

**Request Body:**

```json
{
  "full_name": "Budi Santoso",
  "phone": "+6281234567890",
  "address": "Jl. Merdeka No. 14, Surabaya",
  "latitude": -7.257600,
  "longitude": 112.752200
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Profil berhasil diperbarui",
  "data": {
    "user_id": "550e8400-e29b-41d4-a716-446655440000",
    "full_name": "Budi Santoso",
    "phone": "+6281234567890",
    "address": "Jl. Merdeka No. 14, Surabaya",
    "latitude": -7.257600,
    "longitude": 112.752200,
    "updated_at": "2026-05-30T08:30:00Z"
  }
}
```

---

### 2.3 `PUT /users/me/avatar`

> Upload or update profile photo.

πŸ”’ **Auth Required** β€” Role: `user`, `worker`, `admin`
πŸ“Ž **Content-Type:** `multipart/form-data`

| Field | Type | Required | Description |
|---|---|---|---|
| `avatar` | file | βœ… | Image file (jpg/png, max 5MB) |

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Foto profil berhasil diperbarui",
  "data": {
    "avatar_url": "https://cdn.handydirect.id/avatars/budi_001_v2.jpg"
  }
}
```

---

### 2.4 `PUT /users/me/location`

> Update current location. Used for "Lokasi saat ini" display on Home screen.

πŸ”’ **Auth Required** β€” Role: `user`, `worker`, `admin`

**Request Body:**

```json
{
  "latitude": -7.257500,
  "longitude": 112.752100,
  "address": "Jl. Merdeka No. 12, Surabaya"
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Lokasi berhasil diperbarui"
}
```



---

## 3. Home (User)

> Aggregated data for the User Home screen: greeting, current location, active order banner, promotions, articles, category grid, and featured workers.

---

### 3.1 `GET /home`

> Fetch all data for user home screen. Displayed as: "Selamat datang, Halo Budi!" with location, promo banners, category grid, and "Tukang Unggulan Terdekat".

πŸ”’ **Auth Required** β€” Role: `user`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `latitude` | number | βœ… | β€” | User's current latitude |
| `longitude` | number | βœ… | β€” | User's current longitude |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "user_summary": {
      "full_name": "Budi",
      "avatar_url": "https://cdn.handydirect.id/avatars/budi_001.jpg",
      "current_address": "Jl. Merdeka No. 12"
    },
    "active_order": {
      "order_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "status": "in_progress",
      "worker_name": "Ahmad Jaelani",
      "service_name": "Perbaikan Pipa",
      "eta_minutes": 8
    },
    "promotions": [
      {
        "promo_id": "promo-001",
        "title": "Diskon 20% Jasa AC",
        "description": "Berlaku hingga 31 Oktober 2023",
        "image_url": "https://cdn.handydirect.id/promos/diskon_ac.jpg",
        "cta_label": "Klaim Sekarang",
        "deep_link": "/promo/diskon-ac-20",
        "valid_until": "2023-10-31T23:59:59Z"
      }
    ],
    "articles": [
      {
        "article_id": "art-001",
        "title": "Tips Merawat Atap",
        "thumbnail_url": "https://cdn.handydirect.id/articles/tips_atap.jpg",
        "cta_label": "Baca β†’",
        "slug": "tips-merawat-atap"
      }
    ],
    "service_categories": [
      { "category_id": "cat-01", "name": "AC", "icon_url": "https://cdn.handydirect.id/icons/ac.png", "slug": "ac" },
      { "category_id": "cat-02", "name": "Pipa", "icon_url": "https://cdn.handydirect.id/icons/pipa.png", "slug": "pipa" },
      { "category_id": "cat-03", "name": "Atap", "icon_url": "https://cdn.handydirect.id/icons/atap.png", "slug": "atap" },
      { "category_id": "cat-04", "name": "Listrik", "icon_url": "https://cdn.handydirect.id/icons/listrik.png", "slug": "listrik" },
      { "category_id": "cat-05", "name": "Kunci", "icon_url": "https://cdn.handydirect.id/icons/kunci.png", "slug": "kunci" },
      { "category_id": "cat-06", "name": "Kayu", "icon_url": "https://cdn.handydirect.id/icons/kayu.png", "slug": "kayu" },
      { "category_id": "cat-07", "name": "Cat", "icon_url": "https://cdn.handydirect.id/icons/cat.png", "slug": "cat" },
      { "category_id": "cat-08", "name": "Kebun", "icon_url": "https://cdn.handydirect.id/icons/kebun.png", "slug": "kebun" }
    ],
    "featured_workers": [
      {
        "worker_id": "w-001",
        "full_name": "Ahmad Jaelani",
        "specialization": "Spesialis AC & Listrik",
        "avatar_url": "https://cdn.handydirect.id/workers/ahmad.jpg",
        "rating": 4.9,
        "distance_km": 1.2,
        "completed_jobs": 150,
        "is_verified": true
      },
      {
        "worker_id": "w-002",
        "full_name": "Budi Santoso",
        "specialization": "Pipa & Sanitasi",
        "avatar_url": "https://cdn.handydirect.id/workers/budis.jpg",
        "rating": 4.8,
        "distance_km": 2.5,
        "completed_jobs": 89,
        "is_verified": true
      }
    ]
  }
}
```

---

## 4. Service Categories

> Category grid and service listings. Maps to "Kategori Jasa" section with icons (AC, Pipa, Atap, Listrik, Kunci, Kayu, Cat, Kebun) and "Lihat Semua".

---

### 4.1 `GET /categories`

> Get all service categories.

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `page` | integer | ❌ | `1` | Page number |
| `per_page` | integer | ❌ | `20` | Items per page |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "category_id": "cat-01",
      "name": "AC",
      "slug": "ac",
      "icon_url": "https://cdn.handydirect.id/icons/ac.png",
      "description": "Servis, pemasangan, dan perbaikan AC",
      "display_order": 1,
      "is_active": true
    },
    {
      "category_id": "cat-02",
      "name": "Pipa",
      "slug": "pipa",
      "icon_url": "https://cdn.handydirect.id/icons/pipa.png",
      "description": "Perbaikan dan pemasangan pipa air",
      "display_order": 2,
      "is_active": true
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 20,
    "total": 8,
    "total_pages": 1
  }
}
```

---

### 4.2 `GET /categories/{category_id}/services`

> Get services within a specific category.

**Path Parameters:**

| Param | Type | Description |
|---|---|---|
| `category_id` | uuid | Category ID |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "service_id": "svc-001",
      "category_id": "cat-04",
      "name": "Instalasi Listrik",
      "slug": "instalasi-listrik",
      "description": "Pemasangan dan perbaikan instalasi listrik",
      "icon_url": "https://cdn.handydirect.id/icons/instalasi_listrik.png",
      "base_price": 150000,
      "price_unit": "per kunjungan",
      "estimated_duration": "1-3 jam",
      "is_active": true
    },
    {
      "service_id": "svc-002",
      "category_id": "cat-04",
      "name": "Perbaikan Ledeng",
      "slug": "perbaikan-ledeng",
      "description": "Perbaikan pipa bocor dan ledeng",
      "icon_url": "https://cdn.handydirect.id/icons/perbaikan_ledeng.png",
      "base_price": 120000,
      "price_unit": "per kunjungan",
      "estimated_duration": "1-2 jam",
      "is_active": true
    }
  ]
}
```

---

## 5. Nearby Workers (Tukang Dekat)

> Search and filter nearby workers by location, category, rating, etc. Maps to "Tukang Unggulan Terdekat" and "Lihat Semua" page.

---

### 5.1 `GET /workers/nearby`

> Get nearby workers sorted by distance, rating, or price.

πŸ”’ **Auth Required** β€” Role: `user`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `latitude` | number | βœ… | β€” | User's latitude |
| `longitude` | number | βœ… | β€” | User's longitude |
| `radius_km` | number | ❌ | `10` | Search radius in km |
| `category_id` | uuid | ❌ | β€” | Filter by service category |
| `service_id` | uuid | ❌ | β€” | Filter by specific service |
| `min_rating` | number | ❌ | β€” | Minimum rating (1.0–5.0) |
| `sort_by` | string | ❌ | `distance` | `distance` \| `rating` \| `price` \| `completed_jobs` |
| `sort_order` | string | ❌ | `asc` | `asc` \| `desc` |
| `page` | integer | ❌ | `1` | Page number |
| `per_page` | integer | ❌ | `10` | Items per page |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "worker_id": "w-001",
      "full_name": "Ahmad Jaelani",
      "avatar_url": "https://cdn.handydirect.id/workers/ahmad.jpg",
      "specialization": "Spesialis AC & Listrik",
      "rating": 4.9,
      "total_reviews": 120,
      "completed_jobs": 150,
      "distance_km": 1.2,
      "is_verified": true,
      "is_available": true,
      "base_price": 150000,
      "price_unit": "per kunjungan",
      "services": ["Instalasi Listrik", "Perbaikan Ledeng", "Servis AC"],
      "latitude": -7.260000,
      "longitude": 112.750000
    },
    {
      "worker_id": "w-002",
      "full_name": "Budi Santoso",
      "avatar_url": "https://cdn.handydirect.id/workers/budis.jpg",
      "specialization": "Pipa & Sanitasi",
      "rating": 4.8,
      "total_reviews": 89,
      "completed_jobs": 89,
      "distance_km": 2.5,
      "is_verified": true,
      "is_available": true,
      "base_price": 120000,
      "price_unit": "per kunjungan",
      "services": ["Perbaikan Pipa", "Pipe Repair & Cleaning"],
      "latitude": -7.262000,
      "longitude": 112.748000
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 10,
    "total": 25,
    "total_pages": 3
  }
}
```

---

### 5.2 `GET /workers/search`

> Search workers by keyword. Used by search bar: "Cari tukang atau jenis kerusakan..."

πŸ”’ **Auth Required** β€” Role: `user`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `q` | string | βœ… | β€” | Search keyword (name, specialization, damage type) |
| `latitude` | number | βœ… | β€” | User's latitude |
| `longitude` | number | βœ… | β€” | User's longitude |
| `radius_km` | number | ❌ | `10` | Search radius |
| `page` | integer | ❌ | `1` | β€” |
| `per_page` | integer | ❌ | `10` | β€” |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "worker_id": "w-001",
      "full_name": "Ahmad Jaelani",
      "specialization": "Spesialis AC & Listrik",
      "avatar_url": "https://cdn.handydirect.id/workers/ahmad.jpg",
      "rating": 4.9,
      "total_reviews": 120,
      "completed_jobs": 150,
      "distance_km": 1.2,
      "is_verified": true,
      "is_available": true,
      "base_price": 150000,
      "price_unit": "per kunjungan",
      "services": ["Instalasi Listrik", "Perbaikan Ledeng", "Servis AC"]
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 10,
    "total": 5,
    "total_pages": 1
  }
}
```

---

## 6. Worker Detail (Detail Tukang)

> Detail view of a worker. Maps to the mockup screen showing Ahmad Jaelani's profile with "Terverifikasi" badge, rating 4.9, 120 Ulasan, 150+ Pesanan Selesai, services (Instalasi Listrik, Perbaikan Ledeng, Servis AC), review quotes, and Booking Fee Rp2.000.

---

### 6.1 `GET /workers/{worker_id}`

> Get full worker profile detail.

πŸ”’ **Auth Required** β€” Role: `user`

**Path Parameters:**

| Param | Type | Description |
|---|---|---|
| `worker_id` | uuid | Worker's user ID |

**Query Parameters:**

| Param | Type | Required | Description |
|---|---|---|---|
| `latitude` | number | ❌ | For distance calculation |
| `longitude` | number | ❌ | For distance calculation |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "worker_id": "w-001",
    "full_name": "Ahmad Jaelani",
    "avatar_url": "https://cdn.handydirect.id/workers/ahmad.jpg",
    "cover_photo_url": "https://cdn.handydirect.id/workers/ahmad_cover.jpg",
    "specialization": "Spesialis Kelistrikan & Ledeng",
    "bio": "Berpengalaman lebih dari 8 tahun dalam menangani instalasi listrik rumah tangga dan perbaikan pipa bocor dengan standar keamanan tinggi.",
    "is_verified": true,
    "verification_status": "verified",
    "rating": 4.9,
    "total_reviews": 120,
    "completed_jobs": 150,
    "distance_km": 1.2,
    "is_available": true,
    "member_since": "2021-03-10T00:00:00Z",
    "booking_fee": 2000,
    "services": [
      {
        "service_id": "svc-001",
        "name": "Instalasi Listrik",
        "icon_url": "https://cdn.handydirect.id/icons/listrik.png",
        "base_price": 150000,
        "price_unit": "per kunjungan"
      },
      {
        "service_id": "svc-002",
        "name": "Perbaikan Ledeng",
        "icon_url": "https://cdn.handydirect.id/icons/ledeng.png",
        "base_price": 120000,
        "price_unit": "per kunjungan"
      },
      {
        "service_id": "svc-003",
        "name": "Servis AC",
        "icon_url": "https://cdn.handydirect.id/icons/ac.png",
        "base_price": 175000,
        "price_unit": "per kunjungan"
      }
    ],
    "top_reviews": [
      {
        "review_id": "rev-001",
        "user_name": "Budi S.",
        "user_location": "Jakarta Selatan",
        "rating": 5,
        "comment": "Tukang Ahmad kerjanya cepat, rapi, dan sangat profesional. Pipa bocor langsung beres dalam sejam.",
        "created_at": "2023-10-15T08:30:00Z"
      }
    ]
  }
}
```

---

### 6.2 `GET /workers/{worker_id}/reviews`

> Get paginated reviews for a worker. Includes rating distribution breakdown.

πŸ”’ **Auth Required** β€” Role: `user`

**Path Parameters:**

| Param | Type | Description |
|---|---|---|
| `worker_id` | uuid | Worker's user ID |

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `rating` | integer | ❌ | β€” | Filter by rating star (1–5) |
| `sort_by` | string | ❌ | `created_at` | `created_at` \| `rating` |
| `sort_order` | string | ❌ | `desc` | `asc` \| `desc` |
| `page` | integer | ❌ | `1` | β€” |
| `per_page` | integer | ❌ | `10` | β€” |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "review_id": "rev-001",
      "order_id": "ord-001",
      "user_name": "Budi S.",
      "user_avatar_url": "https://cdn.handydirect.id/avatars/budi_001.jpg",
      "user_location": "Jakarta Selatan",
      "rating": 5,
      "comment": "Tukang Ahmad kerjanya cepat, rapi, dan sangat profesional. Pipa bocor langsung beres dalam sejam.",
      "tags": ["cepat", "rapi", "profesional"],
      "created_at": "2023-10-15T08:30:00Z"
    }
  ],
  "meta": {
    "average_rating": 4.9,
    "rating_distribution": {
      "5": 95,
      "4": 18,
      "3": 5,
      "2": 1,
      "1": 1
    },
    "current_page": 1,
    "per_page": 10,
    "total": 120,
    "total_pages": 12
  }
}
```

---

### 6.3 `GET /workers/{worker_id}/services`

> Get list of services offered by a worker.

πŸ”’ **Auth Required** β€” Role: `user`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "service_id": "svc-001",
      "name": "Instalasi Listrik",
      "category": "Listrik",
      "description": "Pemasangan dan perbaikan instalasi listrik rumah tangga",
      "base_price": 150000,
      "price_unit": "per kunjungan",
      "estimated_duration": "1-3 jam",
      "icon_url": "https://cdn.handydirect.id/icons/listrik.png"
    },
    {
      "service_id": "svc-002",
      "name": "Perbaikan Ledeng",
      "category": "Pipa",
      "description": "Perbaikan pipa bocor, saluran air, dan ledeng",
      "base_price": 120000,
      "price_unit": "per kunjungan",
      "estimated_duration": "1-2 jam",
      "icon_url": "https://cdn.handydirect.id/icons/ledeng.png"
    },
    {
      "service_id": "svc-003",
      "name": "Servis AC",
      "category": "AC",
      "description": "Pembersihan, isi freon, dan perbaikan AC",
      "base_price": 175000,
      "price_unit": "per kunjungan",
      "estimated_duration": "1-2 jam",
      "icon_url": "https://cdn.handydirect.id/icons/ac.png"
    }
  ]
}
```



---

## 7. Orders β€” User Side

> Order/report creation and management from the user perspective. User selects a worker, creates an order, and can view or cancel orders.

---

### 7.1 `POST /orders`

> Create a new order/report. User selects a worker and service, describes the problem, and provides location.

πŸ”’ **Auth Required** β€” Role: `user`

**Request Body:**

```json
{
  "worker_id": "w-001",
  "service_id": "svc-002",
  "title": "Perbaikan Pipa Bocor",
  "description": "Pipa wastafel bocor di bagian sambungan bawah. Air menetes cukup deras saat keran dinyalakan.",
  "location": {
    "latitude": -7.257500,
    "longitude": 112.752100,
    "address": "Jl. Merdeka No. 12, Surabaya",
    "address_detail": "Lantai 1, dekat dapur, rumah pagar hitam cat putih"
  },
  "preferred_date": "2023-10-25",
  "preferred_time_start": "09:00",
  "preferred_time_end": "12:00",
  "urgency": "normal",
  "photos": ["base64_encoded_photo_string_1"],
  "notes": "Tolong bawa seal tape dan sambungan pipa cadangan"
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `worker_id` | uuid | βœ… | Selected worker's ID |
| `service_id` | uuid | βœ… | Selected service ID |
| `title` | string | βœ… | Order title (max 255 chars) |
| `description` | string | βœ… | Problem description |
| `location` | object | βœ… | Work location details |
| `location.latitude` | number | βœ… | Latitude |
| `location.longitude` | number | βœ… | Longitude |
| `location.address` | string | βœ… | Full address |
| `location.address_detail` | string | ❌ | Additional location details |
| `preferred_date` | date | ❌ | Preferred date (YYYY-MM-DD) |
| `preferred_time_start` | time | ❌ | Preferred start time (HH:MM) |
| `preferred_time_end` | time | ❌ | Preferred end time (HH:MM) |
| `urgency` | enum | ❌ | `normal` \| `urgent` (default: `normal`) |
| `photos` | array | ❌ | Problem photos (max 5, base64 or presigned URL) |
| `notes` | string | ❌ | Additional notes for worker |

**Response `201 Created`:**

```json
{
  "status": "success",
  "message": "Pesanan berhasil dibuat",
  "data": {
    "order_id": "ord-001",
    "order_number": "HD-20231025-001",
    "status": "pending",
    "worker_id": "w-001",
    "worker_name": "Ahmad Jaelani",
    "service_name": "Perbaikan Ledeng",
    "booking_fee": 2000,
    "estimated_base_price": 120000,
    "created_at": "2023-10-25T08:00:00Z"
  }
}
```

---

### 7.2 `GET /orders`

> Get user's order list. Used in the "Orders" tab in bottom navigation.

πŸ”’ **Auth Required** β€” Role: `user`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `status` | string | ❌ | β€” | Filter: `pending` \| `accepted` \| `in_progress` \| `completed` \| `cancelled` \| `rejected` |
| `sort_by` | string | ❌ | `created_at` | `created_at` \| `status` |
| `sort_order` | string | ❌ | `desc` | `asc` \| `desc` |
| `page` | integer | ❌ | `1` | β€” |
| `per_page` | integer | ❌ | `10` | β€” |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "order_id": "ord-005",
      "order_number": "HD-20231024-005",
      "title": "Pipe Repair & Cleaning",
      "status": "completed",
      "worker": {
        "worker_id": "w-002",
        "full_name": "Budi Santoso",
        "avatar_url": "https://cdn.handydirect.id/workers/budis.jpg"
      },
      "service_name": "Pipe Repair & Cleaning",
      "total_price": 350000,
      "created_at": "2023-10-24T14:00:00Z",
      "completed_at": "2023-10-24T15:30:00Z"
    },
    {
      "order_id": "ord-004",
      "order_number": "HD-20231023-004",
      "title": "AC Maintenance",
      "status": "completed",
      "worker": {
        "worker_id": "w-003",
        "full_name": "Siti Aminah",
        "avatar_url": "https://cdn.handydirect.id/workers/siti.jpg"
      },
      "service_name": "AC Maintenance",
      "total_price": 175000,
      "created_at": "2023-10-23T09:00:00Z",
      "completed_at": "2023-10-23T10:15:00Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 10,
    "total": 12,
    "total_pages": 2
  }
}
```

---

### 7.3 `GET /orders/{order_id}`

> Get full detail of a specific order.

πŸ”’ **Auth Required** β€” Role: `user`

**Path Parameters:**

| Param | Type | Description |
|---|---|---|
| `order_id` | uuid | Order ID |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "order_id": "ord-001",
    "order_number": "HD-20231025-001",
    "title": "Perbaikan Pipa Bocor",
    "description": "Pipa wastafel bocor di bagian sambungan bawah. Air menetes cukup deras saat keran dinyalakan.",
    "status": "in_progress",
    "urgency": "normal",
    "worker": {
      "worker_id": "w-001",
      "full_name": "Ahmad Jaelani",
      "avatar_url": "https://cdn.handydirect.id/workers/ahmad.jpg",
      "specialization": "Spesialis Listrik & Air",
      "phone": "+62812xxxxxxx",
      "rating": 4.9,
      "total_reviews": 120,
      "is_verified": true
    },
    "service": {
      "service_id": "svc-002",
      "name": "Perbaikan Ledeng",
      "category": "Pipa"
    },
    "location": {
      "latitude": -7.257500,
      "longitude": 112.752100,
      "address": "Jl. Merdeka No. 12, Surabaya",
      "address_detail": "Lantai 1, dekat dapur"
    },
    "schedule": {
      "preferred_date": "2023-10-25",
      "preferred_time_start": "09:00",
      "preferred_time_end": "12:00"
    },
    "pricing": {
      "booking_fee": 2000,
      "base_service_fee": 150000,
      "total_material_cost": 75000,
      "total_additional_cost": 0,
      "grand_total": 225000
    },
    "photos": [
      "https://cdn.handydirect.id/orders/ord-001/photo_1.jpg"
    ],
    "notes": "Tolong bawa seal tape dan sambungan pipa cadangan",
    "timeline": [
      {
        "event": "order_created",
        "label": "Pesanan Dibuat",
        "timestamp": "2023-10-25T08:00:00Z",
        "is_completed": true
      },
      {
        "event": "order_accepted",
        "label": "Pesanan Diterima Worker",
        "timestamp": "2023-10-25T08:05:00Z",
        "is_completed": true
      },
      {
        "event": "worker_on_the_way",
        "label": "Tukang Menuju Lokasi",
        "timestamp": "2023-10-25T09:00:00Z",
        "is_completed": true
      },
      {
        "event": "worker_arrived",
        "label": "Tukang Tiba di Lokasi",
        "timestamp": "2023-10-25T09:15:00Z",
        "is_completed": true
      },
      {
        "event": "work_in_progress",
        "label": "Pengerjaan Berlangsung",
        "timestamp": "2023-10-25T09:20:00Z",
        "is_completed": true
      }
    ],
    "purchase_summary": {
      "total_items": 3,
      "total_cost": 75000,
      "pending_approval": 1,
      "approved": 2,
      "rejected": 0
    },
    "has_unread_chat": true,
    "can_cancel": true,
    "cancellation_policy": "Pembatalan gratis sebelum worker tiba di lokasi",
    "created_at": "2023-10-25T08:00:00Z",
    "updated_at": "2023-10-25T09:20:00Z"
  }
}
```

---

### 7.4 `POST /orders/{order_id}/cancel`

> Cancel an order (subject to cancellation policy).

πŸ”’ **Auth Required** β€” Role: `user`

**Request Body:**

```json
{
  "reason": "Sudah menemukan tukang lain",
  "reason_category": "found_other_worker"
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `reason` | string | βœ… | Cancellation reason text |
| `reason_category` | enum | ❌ | `changed_mind` \| `found_other_worker` \| `too_long` \| `other` |

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Pesanan berhasil dibatalkan",
  "data": {
    "order_id": "ord-001",
    "status": "cancelled",
    "cancellation_fee": 0,
    "refund_amount": 2000,
    "cancelled_at": "2023-10-25T08:30:00Z"
  }
}
```

**Error `422 Unprocessable Entity`:**

```json
{
  "status": "error",
  "message": "Pesanan tidak dapat dibatalkan karena worker sudah tiba di lokasi",
  "error_code": "CANCEL_NOT_ALLOWED"
}
```

---

## 8. Tracking β€” User Side

> Real-time tracking of worker location, job progress, and status. Maps to the tracking map mockup showing worker location on map with ETA, worker info card, Chat and Telepon buttons, and "Batalkan Pesanan".

---

### 8.1 `GET /orders/{order_id}/tracking`

> Get full tracking state: worker location, ETA, activity status, timeline, purchase summary.

πŸ”’ **Auth Required** β€” Role: `user`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "order_id": "ord-001",
    "order_status": "on_the_way",
    "worker": {
      "worker_id": "w-001",
      "full_name": "Ahmad Jaelani",
      "avatar_url": "https://cdn.handydirect.id/workers/ahmad.jpg",
      "specialization": "Spesialis Listrik & Air",
      "rating": 4.9,
      "total_reviews": 120
    },
    "worker_location": {
      "latitude": -7.259000,
      "longitude": 112.751000,
      "heading": 45.0,
      "updated_at": "2023-10-25T09:12:00Z"
    },
    "user_location": {
      "latitude": -7.257500,
      "longitude": 112.752100,
      "address": "Jl. Merdeka No. 12"
    },
    "eta_minutes": 8,
    "status_label": "Tukang menuju lokasi Anda",
    "activity_status": "on_the_way",
    "timeline": [
      {
        "event": "order_accepted",
        "label": "Pesanan Diterima",
        "timestamp": "2023-10-25T08:05:00Z",
        "is_completed": true
      },
      {
        "event": "worker_on_the_way",
        "label": "Tukang Menuju Lokasi",
        "timestamp": "2023-10-25T09:00:00Z",
        "is_completed": true
      },
      {
        "event": "worker_arrived",
        "label": "Tukang Tiba",
        "timestamp": null,
        "is_completed": false
      },
      {
        "event": "work_in_progress",
        "label": "Pengerjaan",
        "timestamp": null,
        "is_completed": false
      },
      {
        "event": "completed",
        "label": "Selesai",
        "timestamp": null,
        "is_completed": false
      }
    ],
    "purchase_summary": {
      "total_items": 0,
      "total_cost": 0,
      "pending_approval": 0
    },
    "can_cancel": true,
    "can_chat": true,
    "can_call": true
  }
}
```

---

### 8.2 `GET /orders/{order_id}/tracking/location`

> Poll worker's current location. Alternative to WebSocket for simple polling.

πŸ”’ **Auth Required** β€” Role: `user`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "latitude": -7.259000,
    "longitude": 112.751000,
    "heading": 45.0,
    "speed_kmh": 25,
    "eta_minutes": 8,
    "activity_status": "on_the_way",
    "updated_at": "2023-10-25T09:12:00Z"
  }
}
```

---

### 8.3 WebSocket β€” Real-time Tracking (User)

> **Endpoint:** `wss://api.handydirect.id/v1/ws/tracking/{order_id}`

**Authentication:** JWT token as query param `?token=xxx` or in initial connection header.

**Server β†’ Client Events:**

**Location Update:**

```json
{
  "event": "location_update",
  "data": {
    "latitude": -7.258500,
    "longitude": 112.751500,
    "heading": 45.0,
    "eta_minutes": 5,
    "updated_at": "2023-10-25T09:13:00Z"
  }
}
```

**Status Change:**

```json
{
  "event": "status_change",
  "data": {
    "previous_status": "on_the_way",
    "new_status": "arrived",
    "label": "Tukang telah tiba di lokasi Anda",
    "timestamp": "2023-10-25T09:15:00Z"
  }
}
```

**New Purchase Added by Worker:**

```json
{
  "event": "new_purchase",
  "data": {
    "purchase_id": "pur-001",
    "item_name": "Pipa PVC 1/2 Inch",
    "total_price": 50000,
    "status": "pending_approval",
    "needs_user_approval": true
  }
}
```



---

## 9. Purchase Tracking β€” User Side

> User views, approves, rejects, or requests clarification on material/tool purchases made by the worker during the job. Core of the AI-assisted purchase tracking feature.

---

### 9.1 `GET /orders/{order_id}/purchases`

> Get all purchase items for an order, with summary and AI-generated summary text.

πŸ”’ **Auth Required** β€” Role: `user`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `status` | string | ❌ | β€” | Filter: `draft` \| `pending_approval` \| `approved` \| `rejected` \| `needs_clarification` |
| `page` | integer | ❌ | `1` | β€” |
| `per_page` | integer | ❌ | `20` | β€” |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "order_id": "ord-001",
    "purchases": [
      {
        "purchase_id": "pur-001",
        "item_name": "Pipa PVC 1/2 Inch",
        "category": "material",
        "quantity": 2,
        "unit": "meter",
        "unit_price": 25000,
        "total_price": 50000,
        "reason": "Untuk mengganti bagian pipa yang rusak di bawah wastafel",
        "receipt_photo_url": "https://cdn.handydirect.id/receipts/pur-001.jpg",
        "status": "approved",
        "confidence": 0.95,
        "needs_clarification": false,
        "clarification_question": null,
        "risk_flags": [],
        "approved_at": "2023-10-25T10:00:00Z",
        "created_at": "2023-10-25T09:45:00Z"
      },
      {
        "purchase_id": "pur-002",
        "item_name": "Lem Pipa",
        "category": "material",
        "quantity": 1,
        "unit": "kaleng",
        "unit_price": 15000,
        "total_price": 15000,
        "reason": "Untuk merekatkan sambungan pipa baru",
        "receipt_photo_url": null,
        "status": "pending_approval",
        "confidence": 0.92,
        "needs_clarification": false,
        "clarification_question": null,
        "risk_flags": [],
        "approved_at": null,
        "created_at": "2023-10-25T10:15:00Z"
      },
      {
        "purchase_id": "pur-003",
        "item_name": "Alat tidak diketahui",
        "category": "alat",
        "quantity": 1,
        "unit": "pcs",
        "unit_price": 200000,
        "total_price": 200000,
        "reason": "",
        "receipt_photo_url": null,
        "status": "needs_clarification",
        "confidence": 0.30,
        "needs_clarification": true,
        "clarification_question": "Nama alat belum jelas. Mohon worker mengisi nama item, jumlah, dan alasan pembelian.",
        "risk_flags": [
          {
            "type": "data_tidak_lengkap",
            "message": "Nama item dan alasan pembelian belum diisi"
          },
          {
            "type": "harga_tidak_wajar",
            "message": "Harga Rp200.000 terlihat tinggi untuk item tanpa deskripsi"
          }
        ],
        "approved_at": null,
        "created_at": "2023-10-25T10:30:00Z"
      }
    ],
    "summary": {
      "total_items": 3,
      "total_cost": 265000,
      "approved_cost": 50000,
      "pending_cost": 15000,
      "rejected_cost": 0,
      "needs_clarification_cost": 200000,
      "ai_summary": "Total pembelian tambahan saat ini adalah Rp265.000, terdiri dari Pipa PVC 1/2 Inch (disetujui), Lem Pipa (menunggu persetujuan), dan 1 item yang memerlukan klarifikasi."
    }
  },
  "meta": {
    "current_page": 1,
    "per_page": 20,
    "total": 3,
    "total_pages": 1
  }
}
```

---

### 9.2 `GET /orders/{order_id}/purchases/{purchase_id}`

> Get detail of a single purchase item including audit log and AI explanation.

πŸ”’ **Auth Required** β€” Role: `user`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "purchase_id": "pur-001",
    "order_id": "ord-001",
    "item_name": "Pipa PVC 1/2 Inch",
    "category": "material",
    "quantity": 2,
    "unit": "meter",
    "unit_price": 25000,
    "total_price": 50000,
    "reason": "Untuk mengganti bagian pipa yang rusak di bawah wastafel",
    "receipt_photo_url": "https://cdn.handydirect.id/receipts/pur-001.jpg",
    "status": "approved",
    "confidence": 0.95,
    "needs_clarification": false,
    "clarification_question": null,
    "clarification_response": null,
    "ai_explanation": "Worker menambahkan pembelian Pipa PVC 1/2 Inch sebanyak 2 meter seharga Rp25.000/meter karena diperlukan untuk mengganti bagian pipa yang rusak di bawah wastafel.",
    "risk_flags": [],
    "audit_log": [
      {
        "action": "created",
        "actor_type": "worker",
        "actor_name": "Ahmad Jaelani",
        "timestamp": "2023-10-25T09:45:00Z",
        "note": "Pembelian dimasukkan oleh worker"
      },
      {
        "action": "ai_processed",
        "actor_type": "system",
        "actor_name": "AI Assistant",
        "timestamp": "2023-10-25T09:45:05Z",
        "note": "Input dirapikan oleh AI, confidence 95%"
      },
      {
        "action": "submitted",
        "actor_type": "worker",
        "actor_name": "Ahmad Jaelani",
        "timestamp": "2023-10-25T09:45:10Z",
        "note": "Dikirim untuk persetujuan user"
      },
      {
        "action": "approved",
        "actor_type": "user",
        "actor_name": "Budi Santoso",
        "timestamp": "2023-10-25T10:00:00Z",
        "note": null
      }
    ],
    "created_at": "2023-10-25T09:45:00Z",
    "updated_at": "2023-10-25T10:00:00Z"
  }
}
```

---

### 9.3 `PATCH /orders/{order_id}/purchases/{purchase_id}/approve`

> Approve a purchase item. Once approved, it is included in the final invoice.

πŸ”’ **Auth Required** β€” Role: `user`

**Request Body (optional):**

```json
{
  "note": "OK, setuju"
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Pembelian berhasil disetujui",
  "data": {
    "purchase_id": "pur-002",
    "status": "approved",
    "approved_at": "2023-10-25T10:20:00Z"
  }
}
```

---

### 9.4 `PATCH /orders/{order_id}/purchases/{purchase_id}/reject`

> Reject a purchase item.

πŸ”’ **Auth Required** β€” Role: `user`

**Request Body:**

```json
{
  "reason": "Item tidak relevan dengan pekerjaan yang diminta"
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `reason` | string | βœ… | Rejection reason |

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Pembelian ditolak",
  "data": {
    "purchase_id": "pur-003",
    "status": "rejected",
    "rejected_at": "2023-10-25T10:25:00Z"
  }
}
```

---

### 9.5 `PATCH /orders/{order_id}/purchases/{purchase_id}/clarify`

> Request clarification on a purchase. Worker will receive a notification.

πŸ”’ **Auth Required** β€” Role: `user`

**Request Body:**

```json
{
  "question": "Untuk apa alat ini digunakan? Mohon jelaskan nama alat dan kebutuhan spesifiknya."
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Permintaan klarifikasi berhasil dikirim ke worker",
  "data": {
    "purchase_id": "pur-003",
    "status": "needs_clarification",
    "clarification_question": "Untuk apa alat ini digunakan? Mohon jelaskan nama alat dan kebutuhan spesifiknya."
  }
}
```

---

### 9.6 `PATCH /orders/{order_id}/purchases/bulk-approve`

> Approve multiple purchase items at once.

πŸ”’ **Auth Required** β€” Role: `user`

**Request Body:**

```json
{
  "purchase_ids": ["pur-001", "pur-002", "pur-004"],
  "note": "Semua sudah dicek, setuju"
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "3 pembelian berhasil disetujui",
  "data": {
    "approved_count": 3,
    "approved_ids": ["pur-001", "pur-002", "pur-004"]
  }
}
```

---

## 10. Chat β€” User Side

> Real-time chat between user and worker per order. Maps to the chat mockup showing conversation between Budi and Ahmad Jaelani with text messages, image of broken pipe, and status "Sedang menuju lokasi".

---

### 10.1 `GET /orders/{order_id}/chat/messages`

> Get chat message history (cursor-based pagination, newest first).

πŸ”’ **Auth Required** β€” Role: `user`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `before` | string (ISO 8601) | ❌ | β€” | Cursor: fetch messages before this timestamp |
| `limit` | integer | ❌ | `50` | Messages per request (max 100) |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "order_id": "ord-001",
    "worker": {
      "worker_id": "w-001",
      "full_name": "Ahmad Jaelani",
      "avatar_url": "https://cdn.handydirect.id/workers/ahmad.jpg",
      "status_label": "Sedang menuju lokasi"
    },
    "messages": [
      {
        "message_id": "msg-001",
        "sender_type": "user",
        "sender_name": "Budi",
        "content": "Halo Pak Ahmad, apakah sudah di jalan?",
        "message_type": "text",
        "media_url": null,
        "is_read": true,
        "read_at": "2023-10-25T10:15:30Z",
        "created_at": "2023-10-25T10:15:00Z"
      },
      {
        "message_id": "msg-002",
        "sender_type": "worker",
        "sender_name": "Ahmad Jaelani",
        "content": "Halo Pak, iya saya sudah di jalan. Mungkin sekitar 15 menit lagi sampai. Boleh dikirimkan foto pipa yang bocornya lagi supaya saya siapkan alat yang tepat?",
        "message_type": "text",
        "media_url": null,
        "is_read": true,
        "read_at": "2023-10-25T10:17:15Z",
        "created_at": "2023-10-25T10:17:00Z"
      },
      {
        "message_id": "msg-003",
        "sender_type": "user",
        "sender_name": "Budi",
        "content": "Ini pipa yang di bawah wastafel dapur Pak. Bocornya lumayan deras kalau keran dinyalakan.",
        "message_type": "image",
        "media_url": "https://cdn.handydirect.id/chat/img_pipe_leak.jpg",
        "is_read": true,
        "read_at": "2023-10-25T10:20:30Z",
        "created_at": "2023-10-25T10:20:00Z"
      },
      {
        "message_id": "msg-004",
        "sender_type": "worker",
        "sender_name": "Ahmad Jaelani",
        "content": "Baik Pak, saya mengerti. Saya bawa seal tape dan sambungan pipa cadangan. Tunggu sebentar ya.",
        "message_type": "text",
        "media_url": null,
        "is_read": true,
        "read_at": "2023-10-25T10:22:15Z",
        "created_at": "2023-10-25T10:22:00Z"
      }
    ],
    "has_more": false
  }
}
```

---

### 10.2 `POST /orders/{order_id}/chat/messages`

> Send a new chat message.

πŸ”’ **Auth Required** β€” Role: `user`

**Request Body (text):**

```json
{
  "content": "Halo Pak Ahmad, apakah sudah di jalan?",
  "message_type": "text"
}
```

**Request Body (image β€” `multipart/form-data`):**

| Field | Type | Required | Description |
|---|---|---|---|
| `message_type` | string | βœ… | `image` |
| `content` | string | ❌ | Image caption |
| `media` | file | βœ… | Image file (jpg/png, max 10MB) |

**Response `201 Created`:**

```json
{
  "status": "success",
  "data": {
    "message_id": "msg-005",
    "sender_type": "user",
    "sender_name": "Budi",
    "content": "Halo Pak Ahmad, apakah sudah di jalan?",
    "message_type": "text",
    "media_url": null,
    "created_at": "2023-10-25T10:15:00Z"
  }
}
```

---

### 10.3 `PATCH /orders/{order_id}/chat/read`

> Mark all messages in this chat as read.

πŸ”’ **Auth Required** β€” Role: `user`

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Semua pesan ditandai sudah dibaca"
}
```

---

### 10.4 `GET /chats`

> Get list of all active chat conversations. Used in "Chat" tab on bottom navigation.

πŸ”’ **Auth Required** β€” Role: `user`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `page` | integer | ❌ | `1` | β€” |
| `per_page` | integer | ❌ | `20` | β€” |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "order_id": "ord-001",
      "worker": {
        "worker_id": "w-001",
        "full_name": "Ahmad Jaelani",
        "avatar_url": "https://cdn.handydirect.id/workers/ahmad.jpg",
        "is_online": true
      },
      "order_title": "Perbaikan Pipa Bocor",
      "order_status": "in_progress",
      "last_message": {
        "content": "Baik Pak, saya mengerti. Saya bawa seal tape...",
        "sender_type": "worker",
        "message_type": "text",
        "created_at": "2023-10-25T10:22:00Z"
      },
      "unread_count": 0
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 20,
    "total": 3,
    "total_pages": 1
  }
}
```

---

### 10.5 WebSocket β€” Real-time Chat

> **Endpoint:** `wss://api.handydirect.id/v1/ws/chat/{order_id}`

**Server β†’ Client Events:**

**New Message:**

```json
{
  "event": "new_message",
  "data": {
    "message_id": "msg-006",
    "sender_type": "worker",
    "sender_name": "Ahmad Jaelani",
    "content": "Saya sudah sampai di depan rumah Pak.",
    "message_type": "text",
    "media_url": null,
    "created_at": "2023-10-25T10:30:00Z"
  }
}
```

**Typing Indicator:**

```json
{
  "event": "typing",
  "data": {
    "sender_type": "worker",
    "is_typing": true
  }
}
```

**Message Read:**

```json
{
  "event": "message_read",
  "data": {
    "reader_type": "worker",
    "read_until": "2023-10-25T10:20:00Z"
  }
}
```

**Client β†’ Server Events:**

```json
{
  "event": "send_message",
  "data": {
    "content": "Oke Pak, saya bukakan pintu",
    "message_type": "text"
  }
}
```

```json
{
  "event": "typing",
  "data": { "is_typing": true }
}
```

---

## 11. Rating & Review β€” User Side

> User rates the worker after job completion. Maps to the "Bagaimana layanan Budi?" mockup with star rating and comment box.

---

### 11.1 `POST /orders/{order_id}/rating`

> Submit rating and review after job is completed.

πŸ”’ **Auth Required** β€” Role: `user`

**Request Body:**

```json
{
  "rating": 4,
  "comment": "Kerjanya bagus dan rapi, pipa sudah tidak bocor lagi. Terima kasih Pak Ahmad!",
  "tags": ["cepat", "rapi", "profesional"]
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `rating` | integer | βœ… | 1–5 stars |
| `comment` | string | ❌ | Review text (max 1000 chars) |
| `tags` | array | ❌ | Quick tags: `cepat`, `rapi`, `profesional`, `ramah`, etc. |

**Response `201 Created`:**

```json
{
  "status": "success",
  "message": "Rating berhasil dikirim. Terima kasih!",
  "data": {
    "review_id": "rev-010",
    "order_id": "ord-001",
    "worker_id": "w-001",
    "rating": 4,
    "comment": "Kerjanya bagus dan rapi, pipa sudah tidak bocor lagi. Terima kasih Pak Ahmad!",
    "tags": ["cepat", "rapi", "profesional"],
    "created_at": "2023-10-25T12:00:00Z"
  }
}
```

**Error `409 Conflict`:**

```json
{
  "status": "error",
  "message": "Anda sudah memberikan rating untuk pesanan ini",
  "error_code": "RATING_ALREADY_EXISTS"
}
```

---

### 11.2 `GET /orders/{order_id}/rating`

> Get the rating already submitted by user for this order.

πŸ”’ **Auth Required** β€” Role: `user`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "review_id": "rev-010",
    "order_id": "ord-001",
    "worker_id": "w-001",
    "rating": 4,
    "comment": "Kerjanya bagus dan rapi, pipa sudah tidak bocor lagi. Terima kasih Pak Ahmad!",
    "tags": ["cepat", "rapi", "profesional"],
    "created_at": "2023-10-25T12:00:00Z"
  }
}
```

**Error `404 Not Found`:**

```json
{
  "status": "error",
  "message": "Belum ada rating untuk pesanan ini",
  "error_code": "RATING_NOT_FOUND"
}
```



---

## 12. Invoice & Payment β€” User Side

> Invoice detail and payment confirmation. Maps to the "Kerja Selesai!" mockup showing "RINCIAN INVOICE" with Biaya Jasa Dasar, Biaya Material, Total Pembayaran Cash, and payment instruction.

---

### 12.1 `GET /orders/{order_id}/invoice`

> Get final invoice for a completed order.

πŸ”’ **Auth Required** β€” Role: `user`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "invoice_id": "inv-001",
    "order_id": "ord-001",
    "order_number": "HD-20231025-001",
    "invoice_number": "INV-20231025-001",
    "worker": {
      "worker_id": "w-001",
      "full_name": "Ahmad Jaelani",
      "avatar_url": "https://cdn.handydirect.id/workers/ahmad.jpg"
    },
    "service_name": "Perbaikan Ledeng",
    "line_items": {
      "base_service_fee": {
        "label": "Biaya Jasa Dasar",
        "amount": 150000
      },
      "material_cost": {
        "label": "Biaya Material",
        "amount": 75000,
        "breakdown": [
          {
            "item_name": "Pipa PVC 1/2 Inch",
            "quantity": 2,
            "unit": "meter",
            "unit_price": 25000,
            "total_price": 50000
          },
          {
            "item_name": "Lem Pipa",
            "quantity": 1,
            "unit": "kaleng",
            "unit_price": 15000,
            "total_price": 15000
          },
          {
            "item_name": "Seal Tape",
            "quantity": 1,
            "unit": "pcs",
            "unit_price": 10000,
            "total_price": 10000
          }
        ]
      },
      "additional_cost": {
        "label": "Biaya Tambahan",
        "amount": 0
      },
      "booking_fee": {
        "label": "Booking Fee",
        "amount": 2000
      },
      "platform_fee": {
        "label": "Biaya Layanan",
        "amount": 0
      },
      "discount": {
        "label": "Diskon",
        "amount": 0,
        "promo_code": null
      }
    },
    "grand_total": 225000,
    "currency": "IDR",
    "payment_method": "cash",
    "payment_status": "unpaid",
    "payment_instruction": "Silakan lakukan pembayaran secara tunai langsung kepada teknisi kami di lokasi.",
    "ai_report": {
      "work_summary": "Perbaikan pipa bocor di bawah wastafel dapur. Pipa PVC yang rusak diganti dengan yang baru, sambungan diperbaiki dengan lem pipa, dan area sekitar dibersihkan.",
      "materials_used": "Pipa PVC 1/2 Inch 2 meter, Lem Pipa 1 kaleng, Seal Tape 1 pcs",
      "total_service_fee": 150000,
      "total_material_fee": 75000,
      "worker_notes": "Pekerjaan selesai. Pipa sudah tidak bocor. Disarankan pengecekan berkala setiap 6 bulan.",
      "all_purchases_approved": true
    },
    "created_at": "2023-10-25T11:30:00Z"
  }
}
```

---

### 12.2 `POST /orders/{order_id}/payment`

> Confirm or initiate payment.

πŸ”’ **Auth Required** β€” Role: `user`

**Request Body:**

```json
{
  "payment_method": "cash",
  "payment_proof_url": null,
  "promo_code": null
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `payment_method` | enum | βœ… | `cash` \| `bank_transfer` \| `ewallet` |
| `payment_proof_url` | string | ❌ | URL of payment proof (for bank_transfer) |
| `promo_code` | string | ❌ | Promo code to apply |

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Pembayaran berhasil dikonfirmasi",
  "data": {
    "payment_id": "pay-001",
    "order_id": "ord-001",
    "invoice_id": "inv-001",
    "amount": 225000,
    "payment_status": "pending",
    "token": "snap-token-xyz-123",
    "redirect_url": "https://app.sandbox.midtrans.com/snap/v2/vtweb/snap-token-xyz-123",
    "created_at": "2023-10-25T11:45:00Z"
  }
}
```

---

### 12.3 `GET /orders/{order_id}/invoice/pdf`

> Download invoice as PDF file.

πŸ”’ **Auth Required** β€” Role: `user`

**Response `200 OK`:**

```
Content-Type: application/pdf
Content-Disposition: attachment; filename="INV-20231025-001.pdf"
```

---

### 12.4 `POST /orders/{order_id}/payment/sync`

> Pull the latest payment status from Midtrans Sandbox for a given order and update local database status.

πŸ”’ **Auth Required** β€” Role: `user`

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Status pembayaran berhasil disinkronisasi",
  "data": {
    "payment_id": "pay-001",
    "order_id": "ord-001",
    "payment_status": "paid",
    "paid_at": "2023-10-25T11:45:00Z"
  }
}
```

---

## 13. Knowledge / FAQ / Guide

> Information center, tutorials, and FAQ. Maps to "Pusat Bantuan" and article sections on Home.

---

### 13.1 `GET /knowledge/articles`

> Get list of knowledge base articles.

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `category` | string | ❌ | β€” | `faq` \| `guide` \| `tips` \| `safety` \| `payment` |
| `q` | string | ❌ | β€” | Search keyword |
| `page` | integer | ❌ | `1` | β€” |
| `per_page` | integer | ❌ | `10` | β€” |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "article_id": "art-001",
      "title": "Tips Merawat Atap Rumah",
      "slug": "tips-merawat-atap",
      "category": "tips",
      "thumbnail_url": "https://cdn.handydirect.id/articles/tips_atap.jpg",
      "excerpt": "Pelajari cara merawat atap rumah agar tetap awet dan tidak bocor...",
      "read_time_minutes": 5,
      "published_at": "2023-10-20T08:00:00Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 10,
    "total": 15,
    "total_pages": 2
  }
}
```

---

### 13.2 `GET /knowledge/articles/{article_id}`

> Get full article detail.

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "article_id": "art-001",
    "title": "Tips Merawat Atap Rumah",
    "slug": "tips-merawat-atap",
    "category": "tips",
    "thumbnail_url": "https://cdn.handydirect.id/articles/tips_atap.jpg",
    "content_html": "<h2>Perawatan Rutin Atap</h2><p>Atap rumah merupakan bagian penting yang melindungi seluruh bangunan...</p>",
    "read_time_minutes": 5,
    "author": "Tim HandyDirect",
    "tags": ["atap", "perawatan", "rumah"],
    "published_at": "2023-10-20T08:00:00Z"
  }
}
```

---

### 13.3 `GET /knowledge/faq`

> Get FAQ list.

**Query Parameters:**

| Param | Type | Required | Description |
|---|---|---|---|
| `category` | string | ❌ | `general` \| `payment` \| `tracking` \| `security` \| `cancellation` |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "faq_id": "faq-001",
      "question": "Bagaimana cara membatalkan pesanan?",
      "answer": "Anda dapat membatalkan pesanan sebelum worker tiba di lokasi melalui halaman tracking. Pembatalan setelah worker tiba dapat dikenakan biaya pembatalan.",
      "category": "cancellation",
      "display_order": 1
    },
    {
      "faq_id": "faq-002",
      "question": "Apakah biaya material otomatis masuk tagihan?",
      "answer": "Tidak. Setiap pembelian material oleh worker harus disetujui terlebih dahulu oleh Anda sebelum masuk ke tagihan akhir. Anda dapat menyetujui, menolak, atau meminta klarifikasi.",
      "category": "payment",
      "display_order": 2
    },
    {
      "faq_id": "faq-003",
      "question": "Bagaimana cara kerja AI purchase tracking?",
      "answer": "AI membantu merapikan input pembelian dari worker menjadi data terstruktur, memberikan ringkasan biaya, dan mendeteksi pembelian yang tidak wajar. Semua keputusan tetap di tangan Anda.",
      "category": "tracking",
      "display_order": 3
    }
  ]
}
```

---

## 14. Notifications

> Push notifications and in-app notifications for users and workers.

---

### 14.1 `GET /notifications`

> Get notification list for current user.

πŸ”’ **Auth Required** β€” Role: `user`, `worker`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `is_read` | boolean | ❌ | β€” | Filter read/unread |
| `type` | string | ❌ | β€” | `order` \| `purchase` \| `chat` \| `promo` \| `system` \| `payment` |
| `page` | integer | ❌ | `1` | β€” |
| `per_page` | integer | ❌ | `20` | β€” |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "notification_id": "notif-001",
      "type": "purchase",
      "title": "Pembelian Baru Perlu Persetujuan",
      "body": "Ahmad Jaelani menambahkan pembelian Lem Pipa (1 kaleng, Rp15.000). Setujui atau tolak pembelian ini.",
      "is_read": false,
      "deep_link": "/orders/ord-001/purchases/pur-002",
      "metadata": {
        "order_id": "ord-001",
        "purchase_id": "pur-002"
      },
      "created_at": "2023-10-25T10:15:00Z"
    },
    {
      "notification_id": "notif-002",
      "type": "order",
      "title": "Pesanan Diterima",
      "body": "Ahmad Jaelani telah menerima pesanan Anda. Estimasi tiba: 15 menit.",
      "is_read": true,
      "deep_link": "/orders/ord-001/tracking",
      "metadata": {
        "order_id": "ord-001"
      },
      "created_at": "2023-10-25T08:05:00Z"
    }
  ],
  "meta": {
    "unread_count": 3,
    "current_page": 1,
    "per_page": 20,
    "total": 15,
    "total_pages": 1
  }
}
```

---

### 14.2 `PATCH /notifications/{notification_id}/read`

> Mark a single notification as read.

πŸ”’ **Auth Required** β€” Role: `user`, `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Notifikasi ditandai sudah dibaca"
}
```

---

### 14.3 `PATCH /notifications/read-all`

> Mark all notifications as read.

πŸ”’ **Auth Required** β€” Role: `user`, `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Semua notifikasi ditandai sudah dibaca"
}
```



---

# Part C β€” Worker (Tukang) Side

> All endpoints in this section require `role: worker` in the JWT token. Middleware will return `403 Forbidden` if a user with role `user` attempts to access these endpoints.

---

## 15. Worker Profile & Verification

> Worker-specific profile management and identity verification. Maps to "Profil & Keahlian" menu on worker home screen.

---

### 15.1 `GET /worker/profile`

> Get worker's full profile including worker_profiles data.

πŸ”’ **Auth Required** β€” Role: `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "user_id": "w-001",
    "full_name": "Ahmad Jaelani",
    "email": "ahmad@email.com",
    "phone": "+6281234567891",
    "avatar_url": "https://cdn.handydirect.id/workers/ahmad.jpg",
    "address": "Jl. Kebon Jeruk No. 5, Jakarta",
    "latitude": -6.200000,
    "longitude": 106.816666,
    "worker_profile": {
      "specialization": "Spesialis Kelistrikan & Ledeng",
      "bio": "Berpengalaman lebih dari 8 tahun dalam menangani instalasi listrik rumah tangga dan perbaikan pipa bocor dengan standar keamanan tinggi.",
      "cover_photo_url": "https://cdn.handydirect.id/workers/ahmad_cover.jpg",
      "verification_status": "verified",
      "id_card_url": "https://cdn.handydirect.id/verification/ahmad_ktp.jpg",
      "certificate_urls": [
        "https://cdn.handydirect.id/certs/ahmad_cert1.jpg",
        "https://cdn.handydirect.id/certs/ahmad_cert2.jpg"
      ],
      "base_price": 150000,
      "price_unit": "per kunjungan",
      "booking_fee": 2000,
      "rating_avg": 4.9,
      "total_reviews": 120,
      "completed_jobs": 150,
      "is_available": true,
      "verified_at": "2021-04-15T10:00:00Z",
      "member_since": "2021-03-10T00:00:00Z"
    },
    "services": [
      {
        "service_id": "svc-001",
        "name": "Instalasi Listrik",
        "category": "Listrik",
        "custom_price": 160000,
        "is_active": true
      },
      {
        "service_id": "svc-002",
        "name": "Perbaikan Ledeng",
        "category": "Pipa",
        "custom_price": null,
        "is_active": true
      },
      {
        "service_id": "svc-003",
        "name": "Servis AC",
        "category": "AC",
        "custom_price": 175000,
        "is_active": true
      }
    ]
  }
}
```

---

### 15.2 `PUT /worker/profile`

> Update worker profile details.

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "full_name": "Ahmad Jaelani",
  "phone": "+6281234567891",
  "address": "Jl. Kebon Jeruk No. 5, Jakarta",
  "specialization": "Spesialis Kelistrikan & Ledeng",
  "bio": "Berpengalaman lebih dari 8 tahun dalam menangani instalasi listrik rumah tangga dan perbaikan pipa bocor.",
  "base_price": 150000,
  "price_unit": "per kunjungan",
  "services": [
    { "service_id": "svc-001", "custom_price": 160000, "is_active": true },
    { "service_id": "svc-002", "custom_price": null, "is_active": true },
    { "service_id": "svc-003", "custom_price": 175000, "is_active": true }
  ]
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Profil worker berhasil diperbarui",
  "data": {
    "user_id": "w-001",
    "full_name": "Ahmad Jaelani",
    "specialization": "Spesialis Kelistrikan & Ledeng",
    "updated_at": "2026-05-30T09:00:00Z"
  }
}
```

---

### 15.3 `PUT /worker/profile/cover-photo`

> Upload or update worker cover photo.

πŸ”’ **Auth Required** β€” Role: `worker`
πŸ“Ž **Content-Type:** `multipart/form-data`

| Field | Type | Required | Description |
|---|---|---|---|
| `cover_photo` | file | βœ… | Cover image (jpg/png, max 10MB) |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "cover_photo_url": "https://cdn.handydirect.id/workers/ahmad_cover_v2.jpg"
  }
}
```

---

### 15.4 `POST /worker/profile/verification`

> Submit identity verification documents (KTP, certificates).

πŸ”’ **Auth Required** β€” Role: `worker`
πŸ“Ž **Content-Type:** `multipart/form-data`

| Field | Type | Required | Description |
|---|---|---|---|
| `id_card` | file | βœ… | KTP photo (jpg/png, max 5MB) |
| `certificates` | file[] | ❌ | Skill certificates (max 5 files, max 5MB each) |
| `selfie_with_id` | file | ❌ | Selfie holding KTP |

**Response `201 Created`:**

```json
{
  "status": "success",
  "message": "Dokumen verifikasi berhasil dikirim. Proses verifikasi membutuhkan 1-3 hari kerja.",
  "data": {
    "verification_status": "pending",
    "submitted_at": "2026-05-30T09:00:00Z"
  }
}
```

---

### 15.5 `GET /worker/profile/verification`

> Get current verification status.

πŸ”’ **Auth Required** β€” Role: `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "verification_status": "verified",
    "id_card_url": "https://cdn.handydirect.id/verification/ahmad_ktp.jpg",
    "certificate_urls": [
      "https://cdn.handydirect.id/certs/ahmad_cert1.jpg"
    ],
    "submitted_at": "2021-04-10T10:00:00Z",
    "verified_at": "2021-04-15T10:00:00Z",
    "rejection_reason": null
  }
}
```

---

## 16. Home (Worker)

> Worker home dashboard. Maps to the worker home mockup showing: "Bpk. Ahmad" with Terverifikasi badge, "Pendapatan Hari Ini: Rp150.000", availability toggle "Siap Menerima Order", quick menu grid (Riwayat, Penarikan, Profil & Keahlian, Pusat Bantuan), and "Ringkasan Minggu Ini" with Tingkat Penerimaan 95% and Rating Rata-rata 4.9.

---

### 16.1 `GET /worker/home`

> Aggregated dashboard data for worker home screen.

πŸ”’ **Auth Required** β€” Role: `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "worker_summary": {
      "full_name": "Bpk. Ahmad",
      "avatar_url": "https://cdn.handydirect.id/workers/ahmad.jpg",
      "is_verified": true,
      "verification_status": "verified",
      "is_available": true
    },
    "earnings": {
      "today": 150000,
      "this_week": 1250000,
      "this_month": 8450000
    },
    "wallet_balance": 150000,
    "weekly_summary": {
      "acceptance_rate": 95,
      "average_rating": 4.9,
      "jobs_completed_this_week": 12,
      "jobs_completed_this_month": 42
    },
    "incoming_orders_count": 1,
    "active_order": {
      "order_id": "ord-012",
      "title": "Perbaikan Pipa Bocor",
      "status": "in_progress",
      "user_name": "Budi Santoso",
      "started_at": "2023-10-25T10:00:00Z"
    },
    "quick_menu": [
      {
        "id": "history",
        "label": "Riwayat",
        "icon": "clock",
        "subtitle": "12 Selesai bulan ini",
        "deep_link": "/worker/history"
      },
      {
        "id": "withdrawal",
        "label": "Penarikan",
        "icon": "wallet",
        "subtitle": "Tarik dana ke bank",
        "deep_link": "/worker/wallet"
      },
      {
        "id": "profile",
        "label": "Profil & Keahlian",
        "icon": "user-check",
        "subtitle": "Update sertifikat",
        "deep_link": "/worker/profile"
      },
      {
        "id": "help",
        "label": "Pusat Bantuan",
        "icon": "headset",
        "subtitle": "Hubungi CS",
        "deep_link": "/knowledge"
      }
    ]
  }
}
```

---

### 16.2 `PATCH /worker/availability`

> Toggle worker's availability status ("Siap Menerima Order" toggle). When off, worker won't appear in search results and won't receive new orders.

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "is_available": true
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Status ketersediaan berhasil diperbarui",
  "data": {
    "is_available": true,
    "status_label": "Siap Menerima Order",
    "status_description": "Anda terlihat online oleh pelanggan di sekitar."
  }
}
```

---

## 17. Incoming Orders β€” Worker Side

> Incoming order management. Maps to the "Order Baru Masuk!" popup/sheet showing order title, category, description, distance, countdown timer, and "Slide untuk Terima Order".

---

### 17.1 `GET /worker/orders/incoming`

> Get list of pending orders assigned to this worker. Each order has a countdown timer for auto-rejection.

πŸ”’ **Auth Required** β€” Role: `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "order_id": "ord-020",
      "order_number": "HD-20231025-020",
      "title": "Pipa Bocor di Dapur",
      "service_name": "Perbaikan Pipa & Saluran Air",
      "category_name": "Pipa",
      "category_icon_url": "https://cdn.handydirect.id/icons/pipa.png",
      "description_preview": "Pipa wastafel bocor di bagian sambungan bawah. Air menetes cukup deras saat keran dinyalakan.",
      "user": {
        "user_id": "u-005",
        "full_name": "Budi Santoso",
        "avatar_url": "https://cdn.handydirect.id/avatars/budi_001.jpg"
      },
      "location": {
        "address": "Jl. Merdeka Selatan No. 45",
        "distance_km": 1.5
      },
      "urgency": "normal",
      "estimated_base_price": 150000,
      "countdown_seconds": 30,
      "expires_at": "2023-10-25T08:00:30Z",
      "created_at": "2023-10-25T08:00:00Z"
    }
  ]
}
```

---

### 17.2 `GET /worker/orders/incoming/{order_id}`

> Get full detail of an incoming order. Maps to "Detail Order" screen showing map, user info (Budi Santoso, Diterima, 2.4 km), address (Jl. Merdeka Selatan No. 45, Kec. Menteng, Jakarta Pusat), and "Detail Keluhan" section.

πŸ”’ **Auth Required** β€” Role: `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "order_id": "ord-020",
    "order_number": "HD-20231025-020",
    "title": "Pipa Bocor di Dapur",
    "service": {
      "service_id": "svc-002",
      "name": "Perbaikan Pipa & Saluran Air",
      "category": "Pipa",
      "icon_url": "https://cdn.handydirect.id/icons/pipa.png"
    },
    "description": "Pipa wastafel bocor di bagian sambungan bawah. Air merembes cukup deras dari bawah wastafel cuci piring. Sepertinya sambungan pipa P-trap kendor atau pecah. Butuh perbaikan segera karena lantai dapur mulai basah.",
    "status": "pending",
    "urgency": "normal",
    "user": {
      "user_id": "u-005",
      "full_name": "Budi Santoso",
      "avatar_url": "https://cdn.handydirect.id/avatars/budi_001.jpg",
      "phone": "+62812xxxxxxx",
      "total_orders": 5,
      "member_label": "Pelanggan Setia"
    },
    "location": {
      "latitude": -6.186486,
      "longitude": 106.834091,
      "address": "Jl. Merdeka Selatan No. 45",
      "address_detail": "Kec. Menteng, Jakarta Pusat, 10110. (Rumah pagar hitam, cat putih)",
      "distance_km": 2.4
    },
    "schedule": {
      "preferred_date": "2023-10-25",
      "preferred_time_start": "09:00",
      "preferred_time_end": "12:00"
    },
    "photos": [
      "https://cdn.handydirect.id/orders/ord-020/photo_1.jpg"
    ],
    "notes": "Tolong bawa seal tape dan sambungan pipa cadangan",
    "estimated_base_price": 150000,
    "booking_fee": 2000,
    "countdown_seconds": 25,
    "expires_at": "2023-10-25T08:00:30Z",
    "created_at": "2023-10-25T08:00:00Z"
  }
}
```

---

### 17.3 `POST /worker/orders/{order_id}/accept`

> Accept an incoming order. Status changes to `accepted`. Triggers notification to user. Maps to "Slide untuk Terima Order".

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body (optional):**

```json
{
  "estimated_arrival_minutes": 15,
  "note": "Saya akan tiba dalam 15 menit"
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Order berhasil diterima",
  "data": {
    "order_id": "ord-020",
    "status": "accepted",
    "accepted_at": "2023-10-25T08:05:00Z",
    "estimated_arrival_minutes": 15
  }
}
```

**Error `422 Unprocessable Entity`:**

```json
{
  "status": "error",
  "message": "Order sudah expired atau diambil worker lain",
  "error_code": "ORDER_EXPIRED"
}
```

---

### 17.4 `POST /worker/orders/{order_id}/reject`

> Reject an incoming order.

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "reason": "Sedang dalam perjalanan ke order lain",
  "reason_category": "busy"
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `reason` | string | ❌ | Rejection reason text |
| `reason_category` | enum | βœ… | `busy` \| `too_far` \| `not_my_expertise` \| `personal` \| `other` |

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Order ditolak",
  "data": {
    "order_id": "ord-020",
    "status": "rejected",
    "rejected_at": "2023-10-25T08:02:00Z"
  }
}
```



---

## 18. Order Management β€” Worker Side

> Order lifecycle management from the worker perspective. Maps to "Detail Order" (map + user info + Detail Keluhan), "Perbaikan #012 β€” Sedang Diproses" (work detail, material list, cost estimate), "Menunggu Pembayaran" (invoice summary), and action slides ("Geser untuk Mulai Kerja", "Geser untuk Membuat Tagihan", "Geser untuk Selesai").

---

### 18.1 `GET /worker/orders`

> Get all orders assigned to worker (active, completed, cancelled).

πŸ”’ **Auth Required** β€” Role: `worker`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `status` | string | ❌ | β€” | `pending` \| `accepted` \| `on_the_way` \| `arrived` \| `in_progress` \| `completed` \| `cancelled` \| `rejected` |
| `date_from` | date | ❌ | β€” | Filter from date (YYYY-MM-DD) |
| `date_to` | date | ❌ | β€” | Filter to date (YYYY-MM-DD) |
| `sort_by` | string | ❌ | `created_at` | `created_at` \| `status` \| `total_price` |
| `sort_order` | string | ❌ | `desc` | `asc` \| `desc` |
| `page` | integer | ❌ | `1` | β€” |
| `per_page` | integer | ❌ | `10` | β€” |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "order_id": "ord-012",
      "order_number": "HD-20231025-012",
      "title": "Perbaikan Pipa Bocor",
      "status": "in_progress",
      "user": {
        "user_id": "u-005",
        "full_name": "Budi Santoso",
        "avatar_url": "https://cdn.handydirect.id/avatars/budi_001.jpg"
      },
      "service_name": "Perbaikan Pipa & Saluran Air",
      "category_name": "Pipa",
      "location_address": "Jl. Merdeka No.45, Jakarta",
      "total_price": 215000,
      "created_at": "2023-10-25T08:00:00Z",
      "started_at": "2023-10-25T10:00:00Z"
    },
    {
      "order_id": "ord-005",
      "order_number": "HD-20231024-005",
      "title": "Pipe Repair & Cleaning",
      "status": "completed",
      "user": {
        "user_id": "u-003",
        "full_name": "Budi Santoso",
        "avatar_url": "https://cdn.handydirect.id/avatars/budi_003.jpg"
      },
      "service_name": "Pipe Repair & Cleaning",
      "category_name": "Pipa",
      "location_address": "Jl. Sudirman No. 10, Jakarta",
      "total_price": 350000,
      "created_at": "2023-10-24T14:00:00Z",
      "completed_at": "2023-10-24T15:30:00Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 10,
    "total": 150,
    "total_pages": 15
  }
}
```

---

### 18.2 `GET /worker/orders/{order_id}`

> Get full order detail from worker perspective. Maps to "Perbaikan #012 β€” Sedang Diproses" screen: DETAIL PEKERJAAN, lokasi, waktu mulai, Biaya Material list (Pipa PVC, Lem Pipa), estimasi total biaya, informasi pelanggan (Ibu Sarah Wijaya), and action buttons.

πŸ”’ **Auth Required** β€” Role: `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "order_id": "ord-012",
    "order_number": "#012",
    "title": "Perbaikan Pipa Bocor",
    "status": "in_progress",
    "status_label": "Sedang Diproses",
    "description": "Pipa wastafel bocor di bagian sambungan bawah. Air merembes cukup deras dari bawah wastafel cuci piring. Sepertinya sambungan pipa P-trap kendor atau pecah. Butuh perbaikan segera karena lantai dapur mulai basah.",
    "service": {
      "service_id": "svc-002",
      "name": "Perbaikan Pipa & Saluran Air",
      "category": "Pipa",
      "icon_url": "https://cdn.handydirect.id/icons/pipa.png"
    },
    "user": {
      "user_id": "u-005",
      "full_name": "Ibu Sarah Wijaya",
      "avatar_url": "https://cdn.handydirect.id/avatars/sarah.jpg",
      "phone": "+62812xxxxxxx",
      "total_orders": 8,
      "member_label": "Pelanggan Setia"
    },
    "location": {
      "latitude": -6.186486,
      "longitude": 106.834091,
      "address": "Jl. Merdeka No.45, Jakarta",
      "address_detail": "Kec. Menteng, Jakarta Pusat, 10110. (Rumah pagar hitam, cat putih)",
      "distance_km": 2.4
    },
    "schedule": {
      "started_at": "2023-10-25T10:00:00Z",
      "preferred_date": "2023-10-25",
      "preferred_time_start": "09:00",
      "preferred_time_end": "12:00"
    },
    "photos": [
      "https://cdn.handydirect.id/orders/ord-012/photo_1.jpg"
    ],
    "notes": "Tolong bawa seal tape dan sambungan pipa cadangan",
    "pricing": {
      "base_service_fee": 150000,
      "total_material_cost": 65000,
      "total_additional_cost": 0,
      "grand_total": 215000
    },
    "purchases": [
      {
        "purchase_id": "pur-101",
        "item_name": "Pipa PVC 1/2 Inch",
        "category": "material",
        "quantity": 2,
        "unit": "meter",
        "unit_price": 25000,
        "total_price": 50000,
        "status": "approved",
        "icon_url": "https://cdn.handydirect.id/icons/pipa_material.png"
      },
      {
        "purchase_id": "pur-102",
        "item_name": "Lem Pipa",
        "category": "material",
        "quantity": 1,
        "unit": "kaleng",
        "unit_price": 15000,
        "total_price": 15000,
        "status": "approved",
        "icon_url": "https://cdn.handydirect.id/icons/lem_material.png"
      }
    ],
    "timeline": [
      {
        "event": "order_created",
        "label": "Pesanan Dibuat",
        "timestamp": "2023-10-25T08:00:00Z",
        "is_completed": true
      },
      {
        "event": "order_accepted",
        "label": "Order Diterima",
        "timestamp": "2023-10-25T08:05:00Z",
        "is_completed": true
      },
      {
        "event": "worker_on_the_way",
        "label": "Menuju Lokasi",
        "timestamp": "2023-10-25T09:00:00Z",
        "is_completed": true
      },
      {
        "event": "worker_arrived",
        "label": "Tiba di Lokasi",
        "timestamp": "2023-10-25T09:15:00Z",
        "is_completed": true
      },
      {
        "event": "work_in_progress",
        "label": "Pengerjaan Dimulai",
        "timestamp": "2023-10-25T10:00:00Z",
        "is_completed": true
      }
    ],
    "available_actions": [
      {
        "action": "add_purchase",
        "label": "+ Tambah",
        "enabled": true
      },
      {
        "action": "generate_invoice",
        "label": "Geser untuk Membuat Tagihan",
        "enabled": true
      },
      {
        "action": "chat",
        "label": "Hubungi Budi (Chat)",
        "enabled": true
      }
    ],
    "can_add_purchase": true,
    "can_generate_invoice": true,
    "can_chat": true,
    "created_at": "2023-10-25T08:00:00Z",
    "updated_at": "2023-10-25T10:00:00Z"
  }
}
```

---

### 18.3 `PATCH /worker/orders/{order_id}/status`

> Update order status. Maps to action slides:
> - `on_the_way` β†’ Worker starts heading to location
> - `arrived` β†’ Worker arrives at location
> - `in_progress` β†’ "Geser untuk Mulai Kerja"
> - `work_paused` β†’ Pause work (e.g., to buy materials)
> - `completed` β†’ "Geser untuk Selesai" (after invoice generated)

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "status": "in_progress",
  "note": "Mulai pengerjaan",
  "latitude": -6.186486,
  "longitude": 106.834091
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `status` | enum | βœ… | New status: `on_the_way` \| `arrived` \| `in_progress` \| `work_paused` \| `completed` |
| `note` | string | ❌ | Status change note |
| `latitude` | number | ❌ | Current latitude (for location verification) |
| `longitude` | number | ❌ | Current longitude |

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Status order berhasil diperbarui",
  "data": {
    "order_id": "ord-012",
    "previous_status": "arrived",
    "new_status": "in_progress",
    "status_label": "Sedang Diproses",
    "updated_at": "2023-10-25T10:00:00Z"
  }
}
```

**Error `422 Unprocessable Entity`:**

```json
{
  "status": "error",
  "message": "Tidak dapat mengubah status ke 'completed' sebelum invoice dibuat",
  "error_code": "INVALID_STATUS_TRANSITION"
}
```

**Valid State Transitions:**

```
pending β†’ accepted (via /accept endpoint)
accepted β†’ on_the_way
on_the_way β†’ arrived
arrived β†’ in_progress
in_progress β†’ work_paused
work_paused β†’ in_progress
in_progress β†’ completed (requires invoice to be generated first)
```

---

### 18.4 `POST /worker/orders/{order_id}/generate-invoice`

> Generate final invoice. Maps to "Geser untuk Membuat Tagihan". Calculates total from base service fee + approved material costs. After invoiced generated, worker can proceed to "Geser untuk Selesai". Shows "Menunggu Pembayaran" screen with breakdown (Biaya Jasa + Biaya Material = Total Tagihan) and Informasi Pelanggan.

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "base_service_fee": 150000,
  "worker_notes": "Pekerjaan selesai.",
  "total_material_cost": 50000,
  "purchases": [
    {
      "purchase_id": "optional",
      "item_name": "Pipa PVC",
      "category": "material",
      "quantity": 2,
      "unit": "meter",
      "unit_price": 25000,
      "total_price": 50000,
      "reason": "Untuk mengganti pipa pecah"
    }
  ]
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `base_service_fee` | integer | ❌ | Final service fee (optional, defaults to order service fee) |
| `worker_notes` | string | ❌ | Worker's final notes |
| `total_material_cost` | integer | ❌ | Total material cost (optional) |
| `purchases` | array | ❌ | List of materials used |
| `purchases[].purchase_id` | string | ❌ | UUID of existing purchase or "optional"/empty for new |
| `purchases[].item_name` | string | βœ… | Name of the material item |
| `purchases[].category` | string | βœ… | Category of the purchase (e.g. "material") |
| `purchases[].quantity` | number | βœ… | Quantity used |
| `purchases[].unit` | string | βœ… | Unit of measurement |
| `purchases[].unit_price` | integer | βœ… | Price per unit |
| `purchases[].total_price` | integer | βœ… | Total price for the item |
| `purchases[].reason` | string | ❌ | Reason for purchase |

**Response `201 Created`:**

```json
{
  "status": "success",
  "message": "Invoice berhasil dibuat",
  "data": {
    "invoice_id": "inv-012",
    "invoice_number": "INV-20231025-012",
    "order_id": "ord-012",
    "base_service_fee": 150000,
    "total_material_cost": 65000,
    "total_additional_cost": 0,
    "booking_fee": 2000,
    "platform_fee": 0,
    "discount_amount": 0,
    "grand_total": 215000,
    "payment_status": "unpaid",
    "payment_instruction": "Silakan kumpulkan pembayaran tunai dari pelanggan sesuai total di bawah.",
    "user": {
      "user_id": "u-005",
      "full_name": "Ibu Sarah Wijaya",
      "avatar_url": "https://cdn.handydirect.id/avatars/sarah.jpg",
      "member_label": "Pelanggan Setia"
    },
    "summary": {
      "biaya_jasa": 150000,
      "biaya_material": 65000,
      "total_tagihan": 215000
    },
    "created_at": "2023-10-25T11:30:00Z"
  }
}
```

---

## 19. Purchase Management β€” Worker Side (AI-Assisted)

> Worker adds, edits, deletes, and submits material/tool purchases. Includes AI-assisted input processing ("Bantu Rapikan dengan AI") and receipt scanning. Maps to the "+ Tambah" button on the work detail screen, the material list (Pipa PVC, Lem Pipa with delete icons), and AI processing flow.

---

### 19.1 `POST /worker/orders/{order_id}/purchases`

> Add a new purchase item manually. Each field is entered by the worker directly.

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "item_name": "Pipa PVC 1/2 Inch",
  "category": "material",
  "quantity": 2,
  "unit": "meter",
  "unit_price": 25000,
  "total_price": 50000,
  "reason": "Untuk mengganti pipa yang rusak di bawah wastafel",
  "receipt_photo_url": null
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `item_name` | string | βœ… | Item name |
| `category` | enum | βœ… | `material` \| `alat` \| `sparepart` \| `bahan_bangunan` \| `biaya_tambahan` \| `lainnya` |
| `quantity` | number | βœ… | Quantity |
| `unit` | string | βœ… | Unit (pcs, meter, kaleng, sak, liter, etc.) |
| `unit_price` | integer | βœ… | Unit price (Rupiah) |
| `total_price` | integer | βœ… | Total price (Rupiah) |
| `reason` | string | ❌ | Reason for purchase |
| `receipt_photo_url` | string | ❌ | Receipt photo URL |

**Response `201 Created`:**

```json
{
  "status": "success",
  "message": "Pembelian berhasil ditambahkan",
  "data": {
    "purchase_id": "pur-201",
    "item_name": "Pipa PVC 1/2 Inch",
    "category": "material",
    "quantity": 2,
    "unit": "meter",
    "unit_price": 25000,
    "total_price": 50000,
    "reason": "Untuk mengganti pipa yang rusak di bawah wastafel",
    "status": "draft",
    "created_at": "2023-10-25T10:30:00Z"
  }
}
```

---

### 19.2 `POST /worker/orders/{order_id}/purchases/ai-process`

> Send raw text input to AI for structuring β€” "Bantu Rapikan dengan AI" button. The backend processes the input via OpenAI API and returns structured purchase data.

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "raw_input": "Beli pipa PVC 2 meter 2 pcs 50 ribu, semen 1 sak 65.000, baut lem pipa dan sambungan total 85 ribu",
  "order_context": {
    "service_type": "Perbaikan Pipa",
    "description": "Pipa bocor di bawah wastafel"
  }
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `raw_input` | string | βœ… | Raw text input from worker |
| `order_context` | object | ❌ | Context for AI (service type, description) to improve accuracy |

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Input berhasil diproses oleh AI",
  "data": {
    "order_id": "ord-012",
    "items": [
      {
        "item_name": "Pipa PVC",
        "category": "material",
        "quantity": 2,
        "unit": "pcs",
        "unit_price": 25000,
        "total_price": 50000,
        "reason": "Untuk mengganti bagian pipa yang rusak",
        "confidence": 0.95,
        "needs_clarification": false,
        "clarification_question": null
      },
      {
        "item_name": "Semen",
        "category": "bahan_bangunan",
        "quantity": 1,
        "unit": "sak",
        "unit_price": 65000,
        "total_price": 65000,
        "reason": "Untuk menambal area sekitar pipa",
        "confidence": 0.92,
        "needs_clarification": false,
        "clarification_question": null
      },
      {
        "item_name": "Baut, Lem Pipa, Sambungan",
        "category": "material",
        "quantity": 1,
        "unit": "paket",
        "unit_price": 85000,
        "total_price": 85000,
        "reason": "Perlengkapan perbaikan pipa",
        "confidence": 0.78,
        "needs_clarification": true,
        "clarification_question": "Input berisi beberapa item dalam satu harga total. Mohon pisahkan masing-masing item: baut (jumlah? harga?), lem pipa (jumlah? harga?), sambungan (jumlah? harga?)."
      }
    ],
    "summary": "Total 3 entri pembelian senilai Rp200.000. 1 entri perlu dipisahkan agar lebih detail.",
    "risk_flags": [
      {
        "type": "data_tidak_lengkap",
        "message": "Item 'baut, lem pipa, dan sambungan' perlu dipisahkan per item untuk transparansi."
      }
    ],
    "approval_status": "draft"
  }
}
```

---

### 19.3 `POST /worker/orders/{order_id}/purchases/receipt-scan`

> Upload receipt/nota photo for OCR + AI processing. Backend extracts text via OCR, then processes with LLM.

πŸ”’ **Auth Required** β€” Role: `worker`
πŸ“Ž **Content-Type:** `multipart/form-data`

| Field | Type | Required | Description |
|---|---|---|---|
| `receipt_photo` | file | βœ… | Receipt/nota photo (jpg/png, max 10MB) |
| `notes` | string | ❌ | Worker's notes about this receipt |

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Nota berhasil dipindai dan diproses oleh AI",
  "data": {
    "receipt_photo_url": "https://cdn.handydirect.id/receipts/scan_ord012_001.jpg",
    "ocr_raw_text": "Toko Bangunan Jaya\nPipa PVC 1/2\" 2m x Rp25.000 = Rp50.000\nLem Pipa 1 klg = Rp15.000\nTotal: Rp65.000",
    "items": [
      {
        "item_name": "Pipa PVC 1/2 Inch",
        "category": "material",
        "quantity": 2,
        "unit": "meter",
        "unit_price": 25000,
        "total_price": 50000,
        "reason": "Pembelian dari Toko Bangunan Jaya",
        "confidence": 0.93,
        "needs_clarification": false,
        "clarification_question": null
      },
      {
        "item_name": "Lem Pipa",
        "category": "material",
        "quantity": 1,
        "unit": "kaleng",
        "unit_price": 15000,
        "total_price": 15000,
        "reason": "Pembelian dari Toko Bangunan Jaya",
        "confidence": 0.91,
        "needs_clarification": false,
        "clarification_question": null
      }
    ],
    "summary": "Nota dari Toko Bangunan Jaya dengan total Rp65.000 untuk 2 item material.",
    "risk_flags": [],
    "approval_status": "draft"
  }
}
```

---

### 19.4 `PUT /worker/orders/{order_id}/purchases/{purchase_id}`

> Edit an existing purchase item (e.g., after AI processing, worker can correct data).

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "item_name": "Pipa PVC 1/2 Inch",
  "category": "material",
  "quantity": 2,
  "unit": "meter",
  "unit_price": 25000,
  "total_price": 50000,
  "reason": "Untuk mengganti pipa P-trap yang pecah di bawah wastafel"
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Pembelian berhasil diperbarui",
  "data": {
    "purchase_id": "pur-201",
    "item_name": "Pipa PVC 1/2 Inch",
    "category": "material",
    "quantity": 2,
    "unit": "meter",
    "unit_price": 25000,
    "total_price": 50000,
    "reason": "Untuk mengganti pipa P-trap yang pecah di bawah wastafel",
    "status": "draft",
    "updated_at": "2023-10-25T10:35:00Z"
  }
}
```

---

### 19.5 `DELETE /worker/orders/{order_id}/purchases/{purchase_id}`

> Delete a purchase item. Maps to the trash/delete icon (πŸ—‘οΈ) next to each material item in the mockup.

πŸ”’ **Auth Required** β€” Role: `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Pembelian berhasil dihapus"
}
```

**Error `422 Unprocessable Entity`:**

```json
{
  "status": "error",
  "message": "Pembelian yang sudah disetujui user tidak dapat dihapus",
  "error_code": "PURCHASE_ALREADY_APPROVED"
}
```

---

### 19.6 `POST /worker/orders/{order_id}/purchases/{purchase_id}/submit`

> Submit a draft purchase for user approval. Changes status from `draft` to `pending_approval`.

πŸ”’ **Auth Required** β€” Role: `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Pembelian berhasil dikirim untuk persetujuan user",
  "data": {
    "purchase_id": "pur-201",
    "status": "pending_approval",
    "submitted_at": "2023-10-25T10:40:00Z"
  }
}
```

---

### 19.7 `POST /worker/orders/{order_id}/purchases/bulk-submit`

> Submit all draft purchases at once for user approval.

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "purchase_ids": ["pur-201", "pur-202", "pur-203"]
}
```

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "3 pembelian berhasil dikirim untuk persetujuan user",
  "data": {
    "submitted_count": 3,
    "submitted_ids": ["pur-201", "pur-202", "pur-203"]
  }
}
```

---

### 19.8 `PATCH /worker/orders/{order_id}/purchases/{purchase_id}/clarify-response`

> Respond to a user's clarification request on a purchase item.

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "response": "Alat yang dibeli adalah kunci pipa ukuran 14 inch, diperlukan untuk membuka mur sambungan pipa yang sudah karatan.",
  "updated_item_name": "Kunci Pipa 14 Inch",
  "updated_reason": "Diperlukan untuk membuka mur sambungan pipa yang sudah karatan"
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `response` | string | βœ… | Clarification response text |
| `updated_item_name` | string | ❌ | Updated item name (if changed) |
| `updated_reason` | string | ❌ | Updated reason (if changed) |

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Klarifikasi berhasil dikirim. Menunggu persetujuan user.",
  "data": {
    "purchase_id": "pur-203",
    "status": "pending_approval",
    "clarification_response": "Alat yang dibeli adalah kunci pipa ukuran 14 inch...",
    "updated_at": "2023-10-25T10:50:00Z"
  }
}
```



---

## 20. Chat β€” Worker Side

> Chat functionality from the worker perspective. Same data structure as user side; the `sender_type` field differentiates messages. Uses the same WebSocket endpoint as Section 10.5.

---

### 20.1 `GET /worker/orders/{order_id}/chat/messages`

> Get chat history for an order from worker perspective.

πŸ”’ **Auth Required** β€” Role: `worker`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `before` | string (ISO 8601) | ❌ | β€” | Cursor: fetch messages before this timestamp |
| `limit` | integer | ❌ | `50` | Messages per request (max 100) |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "order_id": "ord-012",
    "user": {
      "user_id": "u-005",
      "full_name": "Budi Santoso",
      "avatar_url": "https://cdn.handydirect.id/avatars/budi_001.jpg",
      "status_label": "Pelanggan"
    },
    "messages": [
      {
        "message_id": "msg-001",
        "sender_type": "user",
        "sender_name": "Budi Santoso",
        "content": "Halo Pak Ahmad, apakah sudah di jalan?",
        "message_type": "text",
        "media_url": null,
        "is_read": true,
        "read_at": "2023-10-25T10:15:30Z",
        "created_at": "2023-10-25T10:15:00Z"
      },
      {
        "message_id": "msg-002",
        "sender_type": "worker",
        "sender_name": "Ahmad Jaelani",
        "content": "Halo Pak, iya saya sudah di jalan. Mungkin sekitar 15 menit lagi sampai.",
        "message_type": "text",
        "media_url": null,
        "is_read": true,
        "read_at": "2023-10-25T10:17:15Z",
        "created_at": "2023-10-25T10:17:00Z"
      }
    ],
    "has_more": false
  }
}
```

---

### 20.2 `POST /worker/orders/{order_id}/chat/messages`

> Send a chat message from worker.

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body (text):**

```json
{
  "content": "Saya sudah sampai di depan rumah. Rumah pagar hitam cat putih kan Pak?",
  "message_type": "text"
}
```

**Request Body (image β€” `multipart/form-data`):**

| Field | Type | Required | Description |
|---|---|---|---|
| `message_type` | string | βœ… | `image` |
| `content` | string | ❌ | Image caption |
| `media` | file | βœ… | Image file (jpg/png, max 10MB) |

**Response `201 Created`:**

```json
{
  "status": "success",
  "data": {
    "message_id": "msg-010",
    "sender_type": "worker",
    "sender_name": "Ahmad Jaelani",
    "content": "Saya sudah sampai di depan rumah. Rumah pagar hitam cat putih kan Pak?",
    "message_type": "text",
    "media_url": null,
    "created_at": "2023-10-25T10:30:00Z"
  }
}
```

---

### 20.3 `PATCH /worker/orders/{order_id}/chat/read`

> Mark all messages as read by worker.

πŸ”’ **Auth Required** β€” Role: `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "message": "Semua pesan ditandai sudah dibaca"
}
```

---

### 20.4 `GET /worker/chats`

> Get all active chat conversations for worker. Used in "Chat" tab on worker bottom navigation.

πŸ”’ **Auth Required** β€” Role: `worker`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `page` | integer | ❌ | `1` | β€” |
| `per_page` | integer | ❌ | `20` | β€” |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "order_id": "ord-012",
      "user": {
        "user_id": "u-005",
        "full_name": "Budi Santoso",
        "avatar_url": "https://cdn.handydirect.id/avatars/budi_001.jpg",
        "is_online": true
      },
      "order_title": "Perbaikan Pipa Bocor",
      "order_status": "in_progress",
      "last_message": {
        "content": "Saya sudah sampai di depan rumah...",
        "sender_type": "worker",
        "message_type": "text",
        "created_at": "2023-10-25T10:30:00Z"
      },
      "unread_count": 1
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 20,
    "total": 2,
    "total_pages": 1
  }
}
```

> **Note:** WebSocket chat events use the same endpoint and format as [Section 10.5](#105-websocket--real-time-chat). The `sender_type` field is `worker` for outgoing and `user` for incoming messages.

---

## 21. Rating β€” Worker Side (Rate Customer)

> Worker rates the customer after job completion. Maps to the "Beri Rating Konsumen" mockup: showing customer avatar (Ibu Sarah Wijaya), star rating, text input "Catatan tentang Konsumen", and tag chips (Ramah, Lokasi Akurat, Pembayaran Cepat).

---

### 21.1 `POST /worker/orders/{order_id}/customer-rating`

> Submit rating and review for the customer.

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "rating": 5,
  "comment": "Lokasi mudah ditemukan, sangat ramah dan pembayaran langsung tunai tanpa masalah.",
  "tags": ["Ramah", "Lokasi Akurat", "Pembayaran Cepat"]
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `rating` | integer | βœ… | 1–5 stars |
| `comment` | string | ❌ | Comment about customer (max 500 chars) |
| `tags` | array | ❌ | Quick tags: `Ramah`, `Lokasi Akurat`, `Pembayaran Cepat`, `Responsif`, `Kooperatif` |

**Response `201 Created`:**

```json
{
  "status": "success",
  "message": "Rating konsumen berhasil dikirim",
  "data": {
    "customer_review_id": "crev-001",
    "order_id": "ord-012",
    "user_id": "u-005",
    "rating": 5,
    "comment": "Lokasi mudah ditemukan, sangat ramah dan pembayaran langsung tunai tanpa masalah.",
    "tags": ["Ramah", "Lokasi Akurat", "Pembayaran Cepat"],
    "created_at": "2023-10-25T12:10:00Z"
  }
}
```

**Error `409 Conflict`:**

```json
{
  "status": "error",
  "message": "Anda sudah memberikan rating untuk konsumen pada pesanan ini",
  "error_code": "CUSTOMER_RATING_ALREADY_EXISTS"
}
```

---

### 21.2 `GET /worker/orders/{order_id}/customer-rating`

> Get the customer rating already submitted by worker for this order.

πŸ”’ **Auth Required** β€” Role: `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "customer_review_id": "crev-001",
    "order_id": "ord-012",
    "user_id": "u-005",
    "user_name": "Ibu Sarah Wijaya",
    "user_avatar_url": "https://cdn.handydirect.id/avatars/sarah.jpg",
    "rating": 5,
    "comment": "Lokasi mudah ditemukan, sangat ramah dan pembayaran langsung tunai tanpa masalah.",
    "tags": ["Ramah", "Lokasi Akurat", "Pembayaran Cepat"],
    "created_at": "2023-10-25T12:10:00Z"
  }
}
```

---

## 22. History & Statistics β€” Worker Side

> Worker's job history and performance statistics. Maps to the "Orders" tab mockup showing "Pendapatan Bulanan: Rp 8.450.000", filter tabs (Bulanan/Mingguan/Harian), and Job History list with each job's date, time, price, and COMPLETED status.

---

### 22.1 `GET /worker/history`

> Get worker's order history with earnings summary and period filter.

πŸ”’ **Auth Required** β€” Role: `worker`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `period` | string | ❌ | `monthly` | `daily` \| `weekly` \| `monthly` |
| `status` | string | ❌ | β€” | `completed` \| `cancelled` \| `in_progress` |
| `date_from` | date | ❌ | β€” | Start date (YYYY-MM-DD) |
| `date_to` | date | ❌ | β€” | End date (YYYY-MM-DD) |
| `sort_by` | string | ❌ | `created_at` | `created_at` \| `total_price` |
| `sort_order` | string | ❌ | `desc` | `asc` \| `desc` |
| `page` | integer | ❌ | `1` | β€” |
| `per_page` | integer | ❌ | `10` | β€” |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "earnings_summary": {
      "period": "monthly",
      "period_label": "Pendapatan Bulanan",
      "total_earnings": 8450000,
      "currency": "IDR"
    },
    "orders": [
      {
        "order_id": "ord-005",
        "order_number": "HD-20231024-005",
        "title": "Pipe Repair & Cleaning",
        "status": "completed",
        "user": {
          "full_name": "Budi Santoso",
          "avatar_url": "https://cdn.handydirect.id/avatars/budi_001.jpg"
        },
        "service_name": "Pipe Repair & Cleaning",
        "category_name": "Pipa",
        "category_icon_url": "https://cdn.handydirect.id/icons/pipa.png",
        "total_price": 350000,
        "date": "2023-10-24",
        "time_range": "14:00 - 15:30",
        "duration_label": "1.5 jam",
        "created_at": "2023-10-24T14:00:00Z",
        "completed_at": "2023-10-24T15:30:00Z"
      },
      {
        "order_id": "ord-004",
        "order_number": "HD-20231023-004",
        "title": "AC Maintenance",
        "status": "completed",
        "user": {
          "full_name": "Siti Aminah",
          "avatar_url": "https://cdn.handydirect.id/avatars/siti.jpg"
        },
        "service_name": "AC Maintenance",
        "category_name": "AC",
        "category_icon_url": "https://cdn.handydirect.id/icons/ac.png",
        "total_price": 175000,
        "date": "2023-10-23",
        "time_range": "09:00 - 10:15",
        "duration_label": "1.25 jam",
        "created_at": "2023-10-23T09:00:00Z",
        "completed_at": "2023-10-23T10:15:00Z"
      },
      {
        "order_id": "ord-003",
        "order_number": "HD-20231021-003",
        "title": "Interior Wall Painting",
        "status": "completed",
        "user": {
          "full_name": "Andi Wijaya",
          "avatar_url": "https://cdn.handydirect.id/avatars/andi.jpg"
        },
        "service_name": "Interior Wall Painting",
        "category_name": "Cat",
        "category_icon_url": "https://cdn.handydirect.id/icons/cat.png",
        "total_price": 1200000,
        "date": "2023-10-21",
        "time_range": "Full Day",
        "duration_label": "Full Day",
        "created_at": "2023-10-21T08:00:00Z",
        "completed_at": "2023-10-21T17:00:00Z"
      },
      {
        "order_id": "ord-002",
        "order_number": "HD-20231020-002",
        "title": "Door Hinge Replacement",
        "status": "completed",
        "user": {
          "full_name": "Linda Hartono",
          "avatar_url": "https://cdn.handydirect.id/avatars/linda.jpg"
        },
        "service_name": "Door Hinge Replacement",
        "category_name": "Kayu",
        "category_icon_url": "https://cdn.handydirect.id/icons/kayu.png",
        "total_price": 120000,
        "date": "2023-10-20",
        "time_range": "16:30 - 17:15",
        "duration_label": "45 menit",
        "created_at": "2023-10-20T16:30:00Z",
        "completed_at": "2023-10-20T17:15:00Z"
      }
    ]
  },
  "meta": {
    "current_page": 1,
    "per_page": 10,
    "total": 42,
    "total_pages": 5
  }
}
```

---

### 22.2 `GET /worker/statistics`

> Get worker performance statistics.

πŸ”’ **Auth Required** β€” Role: `worker`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `period` | string | ❌ | `monthly` | `daily` \| `weekly` \| `monthly` \| `yearly` \| `all_time` |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "period": "monthly",
    "period_label": "Bulan Ini",
    "earnings": {
      "total": 8450000,
      "service_fees": 6300000,
      "material_reimbursements": 2150000,
      "bonuses": 0,
      "currency": "IDR"
    },
    "jobs": {
      "total": 42,
      "completed": 40,
      "cancelled": 1,
      "in_progress": 1,
      "rejected": 3
    },
    "performance": {
      "acceptance_rate": 95,
      "completion_rate": 98,
      "average_rating": 4.9,
      "total_reviews": 38,
      "on_time_arrival_rate": 92,
      "average_response_time_seconds": 25
    },
    "top_services": [
      { "service_name": "Perbaikan Pipa", "count": 15, "earnings": 3200000 },
      { "service_name": "Servis AC", "count": 12, "earnings": 2800000 },
      { "service_name": "Instalasi Listrik", "count": 8, "earnings": 1650000 }
    ],
    "daily_breakdown": [
      { "date": "2023-10-25", "jobs": 2, "earnings": 350000 },
      { "date": "2023-10-24", "jobs": 1, "earnings": 350000 },
      { "date": "2023-10-23", "jobs": 2, "earnings": 295000 }
    ]
  }
}
```

---

## 23. Wallet β€” Worker Side

> Worker's digital wallet for earnings and withdrawals. Maps to "Penarikan" menu on worker home, showing saldo wallet balance and transaction history.

---

### 23.1 `GET /worker/wallet`

> Get wallet balance and summary.

πŸ”’ **Auth Required** β€” Role: `worker`

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "wallet_id": "wal-001",
    "balance": 150000,
    "total_earnings": 8450000,
    "total_withdrawn": 8300000,
    "pending_earnings": 215000,
    "is_active": true,
    "currency": "IDR",
    "updated_at": "2023-10-25T11:45:00Z"
  }
}
```

---

### 23.2 `GET /worker/wallet/transactions`

> Get wallet transaction history.

πŸ”’ **Auth Required** β€” Role: `worker`

**Query Parameters:**

| Param | Type | Required | Default | Description |
|---|---|---|---|---|
| `type` | string | ❌ | β€” | `earning` \| `withdrawal` \| `refund` \| `bonus` \| `fee` |
| `status` | string | ❌ | β€” | `pending` \| `completed` \| `failed` \| `cancelled` |
| `date_from` | date | ❌ | β€” | Start date |
| `date_to` | date | ❌ | β€” | End date |
| `page` | integer | ❌ | `1` | β€” |
| `per_page` | integer | ❌ | `20` | β€” |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": [
    {
      "transaction_id": "tx-001",
      "type": "earning",
      "amount": 350000,
      "balance_before": 8100000,
      "balance_after": 8450000,
      "description": "Pendapatan dari order #HD-20231024-005 (Pipe Repair & Cleaning)",
      "order_id": "ord-005",
      "order_number": "HD-20231024-005",
      "status": "completed",
      "completed_at": "2023-10-24T16:00:00Z",
      "created_at": "2023-10-24T15:30:00Z"
    },
    {
      "transaction_id": "tx-002",
      "type": "withdrawal",
      "amount": 5000000,
      "balance_before": 5150000,
      "balance_after": 150000,
      "description": "Penarikan ke rekening BCA ****1234",
      "order_id": null,
      "order_number": null,
      "status": "completed",
      "completed_at": "2023-10-23T14:00:00Z",
      "created_at": "2023-10-23T12:00:00Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "per_page": 20,
    "total": 85,
    "total_pages": 5
  }
}
```

---

### 23.3 `POST /worker/wallet/withdraw`

> Create a withdrawal request. Maps to "Penarikan β€” Tarik dana ke bank".

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "amount": 5000000,
  "bank_name": "BCA",
  "account_number": "1234567890",
  "account_holder_name": "Ahmad Jaelani",
  "notes": "Penarikan bulanan"
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `amount` | integer | βœ… | Withdrawal amount (Rupiah, min 50000) |
| `bank_name` | string | βœ… | Bank name (BCA, BNI, BRI, Mandiri, etc.) |
| `account_number` | string | βœ… | Bank account number |
| `account_holder_name` | string | βœ… | Account holder name |
| `notes` | string | ❌ | Notes |

**Response `201 Created`:**

```json
{
  "status": "success",
  "message": "Permintaan penarikan berhasil dibuat. Dana akan diproses dalam 1-3 hari kerja.",
  "data": {
    "transaction_id": "tx-100",
    "type": "withdrawal",
    "amount": 5000000,
    "balance_before": 5150000,
    "balance_after": 150000,
    "status": "pending",
    "estimated_completion": "2023-10-28T00:00:00Z",
    "created_at": "2023-10-25T12:00:00Z"
  }
}
```

**Error `422 Unprocessable Entity`:**

```json
{
  "status": "error",
  "message": "Saldo tidak mencukupi untuk penarikan. Saldo saat ini: Rp150.000",
  "error_code": "INSUFFICIENT_BALANCE"
}
```

---

## 24. Worker Location Updates

> Worker sends periodic location updates while en route or during a job. These updates are pushed to the user via WebSocket.

---

### 24.1 `PUT /worker/location`

> Update worker's current location. Called periodically (every 5-10 seconds) by the mobile app when worker is on the way to a job.

πŸ”’ **Auth Required** β€” Role: `worker`

**Request Body:**

```json
{
  "latitude": -6.188000,
  "longitude": 106.832000,
  "heading": 180.0,
  "speed_kmh": 30,
  "accuracy_meters": 5.0,
  "order_id": "ord-012"
}
```

| Field | Type | Required | Description |
|---|---|---|---|
| `latitude` | number | βœ… | Current latitude |
| `longitude` | number | βœ… | Current longitude |
| `heading` | number | ❌ | Compass heading in degrees (0-360) |
| `speed_kmh` | number | ❌ | Current speed in km/h |
| `accuracy_meters` | number | ❌ | GPS accuracy in meters |
| `order_id` | uuid | ❌ | Active order ID (if en route to order) |

**Response `200 OK`:**

```json
{
  "status": "success",
  "data": {
    "latitude": -6.188000,
    "longitude": 106.832000,
    "eta_minutes": 5,
    "distance_remaining_km": 1.2,
    "updated_at": "2023-10-25T09:12:00Z"
  }
}
```



---

# Part D β€” Shared

---

## 25. WebSocket Events

> Summary of all real-time WebSocket channels and their events.

### 25.1 WebSocket Channels

| Channel | Endpoint | Auth | Description |
|---|---|---|---|
| Tracking | `wss://api.handydirect.id/v1/ws/tracking/{order_id}` | JWT (query param) | Real-time worker location, status changes, purchase notifications |
| Chat | `wss://api.handydirect.id/v1/ws/chat/{order_id}` | JWT (query param) | Real-time messaging between user and worker |

### 25.2 Tracking Events

| Direction | Event | Description |
|---|---|---|
| Server β†’ Client | `location_update` | Worker location updated (lat, lng, heading, eta) |
| Server β†’ Client | `status_change` | Order status changed (e.g., arrived, in_progress) |
| Server β†’ Client | `new_purchase` | Worker added a new purchase item |
| Server β†’ Client | `purchase_status_change` | Purchase approved/rejected by user |
| Server β†’ Client | `order_completed` | Job completed, invoice ready |

### 25.3 Chat Events

| Direction | Event | Description |
|---|---|---|
| Server β†’ Client | `new_message` | New chat message received |
| Server β†’ Client | `typing` | Counterpart is typing |
| Server β†’ Client | `message_read` | Messages have been read |
| Client β†’ Server | `send_message` | Send a text message |
| Client β†’ Server | `typing` | Send typing indicator |

### 25.4 Connection Management

```json
// Connection
{
  "url": "wss://api.handydirect.id/v1/ws/tracking/{order_id}?token=<jwt_token>",
  "protocols": ["v1.handydirect"]
}

// Heartbeat (every 30 seconds)
{ "event": "ping" }
{ "event": "pong" }

// Connection error
{
  "event": "error",
  "data": {
    "code": "TOKEN_EXPIRED",
    "message": "Token expired, please refresh"
  }
}
```

---

## 26. Enums & Shared Schemas

### 26.1 Enums

```yaml
OrderStatus:
  enum: [pending, accepted, on_the_way, arrived, in_progress, work_paused, completed, cancelled, rejected, waiting_payment, waiting_for_payment, paid]

PurchaseStatus:
  enum: [draft, pending_approval, approved, rejected, needs_clarification]

PurchaseCategory:
  enum: [material, alat, sparepart, bahan_bangunan, biaya_tambahan, lainnya]

RiskFlagType:
  enum: [harga_tidak_wajar, item_tidak_relevan, data_tidak_lengkap, nota_tidak_jelas, duplikat, alasan_tidak_lengkap]

MessageType:
  enum: [text, image, system]

PaymentMethod:
  enum: [cash, bank_transfer, ewallet]

PaymentStatus:
  enum: [unpaid, pending, paid, refunded, waiting_payment, waiting_for_payment]

Urgency:
  enum: [normal, urgent]

UserRole:
  enum: [user, worker, admin]

VerificationStatus:
  enum: [unverified, pending, verified, rejected]

NotificationType:
  enum: [order, purchase, chat, promo, system, payment]

WalletTransactionType:
  enum: [earning, withdrawal, refund, bonus, fee]

WalletTransactionStatus:
  enum: [pending, completed, failed, cancelled]

OrderCancelReason:
  enum: [changed_mind, found_other_worker, too_long, other]

OrderRejectReason:
  enum: [busy, too_far, not_my_expertise, personal, other]

AuditAction:
  enum: [created, ai_processed, submitted, approved, rejected, clarification_requested, clarification_responded, edited, deleted]
```

### 26.2 Standard Response Schema

**Success Response:**

```json
{
  "status": "success",
  "message": "Optional success message",
  "data": {},
  "meta": {
    "current_page": 1,
    "per_page": 10,
    "total": 100,
    "total_pages": 10
  }
}
```

**Error Response:**

```json
{
  "status": "error",
  "message": "Human-readable error message",
  "error_code": "MACHINE_READABLE_CODE",
  "errors": [
    {
      "field": "email",
      "message": "Email sudah terdaftar"
    }
  ]
}
```

### 26.3 AI Purchase Output Schema

> Structured JSON schema returned by the LLM for purchase tracking processing.

```json
{
  "order_id": "string (UUID)",
  "items": [
    {
      "item_name": "string",
      "category": "material | alat | sparepart | bahan_bangunan | biaya_tambahan | lainnya",
      "quantity": "number",
      "unit": "string",
      "unit_price": "number (integer, Rupiah)",
      "total_price": "number (integer, Rupiah)",
      "reason": "string",
      "confidence": "number (0.00 – 1.00)",
      "needs_clarification": "boolean",
      "clarification_question": "string | null"
    }
  ],
  "summary": "string (human-readable summary of all purchases)",
  "risk_flags": [
    {
      "type": "harga_tidak_wajar | item_tidak_relevan | data_tidak_lengkap | nota_tidak_jelas | duplikat | alasan_tidak_lengkap",
      "message": "string"
    }
  ],
  "approval_status": "draft"
}
```

---

## 27. Error Responses

### 27.1 Standard Error Format

All error responses follow the same structure:

```json
{
  "status": "error",
  "message": "Deskripsi error yang mudah dipahami",
  "error_code": "KODE_ERROR_MESIN",
  "errors": []
}
```

### 27.2 Error Examples by Status Code

**`400 Bad Request` β€” Invalid Parameters:**

```json
{
  "status": "error",
  "message": "Validasi gagal",
  "error_code": "VALIDATION_ERROR",
  "errors": [
    { "field": "email", "message": "Format email tidak valid" },
    { "field": "password", "message": "Password minimal 8 karakter" }
  ]
}
```

**`401 Unauthorized` β€” Invalid/Expired Token:**

```json
{
  "status": "error",
  "message": "Token tidak valid atau sudah expired",
  "error_code": "UNAUTHORIZED"
}
```

**`403 Forbidden` β€” Role Mismatch:**

```json
{
  "status": "error",
  "message": "Anda tidak memiliki akses ke endpoint ini. Dibutuhkan role: worker",
  "error_code": "FORBIDDEN"
}
```

**`404 Not Found`:**

```json
{
  "status": "error",
  "message": "Order dengan ID ord-999 tidak ditemukan",
  "error_code": "NOT_FOUND"
}
```

**`409 Conflict` β€” Duplicate Resource:**

```json
{
  "status": "error",
  "message": "Anda sudah memberikan rating untuk pesanan ini",
  "error_code": "RATING_ALREADY_EXISTS"
}
```

**`422 Unprocessable Entity` β€” Business Logic Error:**

```json
{
  "status": "error",
  "message": "Pesanan tidak dapat dibatalkan karena worker sudah tiba di lokasi",
  "error_code": "CANCEL_NOT_ALLOWED"
}
```

**`429 Too Many Requests` β€” Rate Limited:**

```json
{
  "status": "error",
  "message": "Terlalu banyak request. Coba lagi dalam 60 detik.",
  "error_code": "RATE_LIMITED"
}
```

**`500 Internal Server Error`:**

```json
{
  "status": "error",
  "message": "Terjadi kesalahan internal. Silakan coba lagi nanti.",
  "error_code": "INTERNAL_ERROR"
}
```

### 27.3 Error Code Reference

| Error Code | HTTP | Description |
|---|---|---|
| `VALIDATION_ERROR` | 400 | One or more fields failed validation |
| `UNAUTHORIZED` | 401 | Missing, invalid, or expired JWT token |
| `INVALID_CREDENTIALS` | 401 | Wrong email/password combination |
| `FORBIDDEN` | 403 | Authenticated but not authorized (role mismatch) |
| `NOT_FOUND` | 404 | Requested resource does not exist |
| `EMAIL_ALREADY_EXISTS` | 409 | Email already registered |
| `PHONE_ALREADY_EXISTS` | 409 | Phone number already registered |
| `RATING_ALREADY_EXISTS` | 409 | Rating already submitted for this order |
| `CUSTOMER_RATING_ALREADY_EXISTS` | 409 | Worker already rated customer for this order |
| `CANCEL_NOT_ALLOWED` | 422 | Order cannot be cancelled at current status |
| `ORDER_EXPIRED` | 422 | Order acceptance window has expired |
| `INVALID_STATUS_TRANSITION` | 422 | Invalid order status transition |
| `PURCHASE_ALREADY_APPROVED` | 422 | Cannot delete/edit approved purchase |
| `INSUFFICIENT_BALANCE` | 422 | Wallet balance too low for withdrawal |
| `INVOICE_NOT_GENERATED` | 422 | Cannot complete order before invoice is generated |
| `RATE_LIMITED` | 429 | Too many requests |
| `INTERNAL_ERROR` | 500 | Unexpected server error |

---

## 28. Endpoint Summary Table

### Part A β€” Authentication (Any Role)

| # | Method | Endpoint | Role | Description |
|---|---|---|---|---|
| 1 | POST | `/auth/register` | any | Register new account |
| 2 | POST | `/auth/login` | any | Login |
| 3 | POST | `/auth/refresh` | any | Refresh access token |
| 4 | POST | `/auth/logout` | auth | Logout |
| 5 | POST | `/auth/forgot-password` | any | Request password reset |
| 6 | POST | `/auth/reset-password` | any | Reset password |

### Part B β€” User Profile (Any Authenticated Role)

| # | Method | Endpoint | Role | Description |
|---|---|---|---|---|
| 7 | GET | `/users/me` | auth | Get own profile |
| 8 | PUT | `/users/me` | auth | Update profile |
| 9 | PUT | `/users/me/avatar` | auth | Upload avatar |
| 10 | PUT | `/users/me/location` | auth | Update location |

### Part C β€” User (Customer) Endpoints

| # | Method | Endpoint | Role | Description |
|---|---|---|---|---|
| 11 | GET | `/home` | user | Home screen data |
| 12 | GET | `/categories` | any | List categories |
| 13 | GET | `/categories/{id}/services` | any | Services in category |
| 14 | GET | `/workers/nearby` | user | Nearby workers |
| 15 | GET | `/workers/search` | user | Search workers |
| 16 | GET | `/workers/{id}` | user | Worker detail |
| 17 | GET | `/workers/{id}/reviews` | user | Worker reviews |
| 18 | GET | `/workers/{id}/services` | user | Worker services |
| 19 | POST | `/orders` | user | Create order |
| 20 | GET | `/orders` | user | List orders |
| 21 | GET | `/orders/{id}` | user | Order detail |
| 22 | POST | `/orders/{id}/cancel` | user | Cancel order |
| 23 | GET | `/orders/{id}/tracking` | user | Tracking data |
| 24 | GET | `/orders/{id}/tracking/location` | user | Worker location (poll) |
| 25 | GET | `/orders/{id}/purchases` | user | List purchases |
| 26 | GET | `/orders/{id}/purchases/{pid}` | user | Purchase detail |
| 27 | PATCH | `/orders/{id}/purchases/{pid}/approve` | user | Approve purchase |
| 28 | PATCH | `/orders/{id}/purchases/{pid}/reject` | user | Reject purchase |
| 29 | PATCH | `/orders/{id}/purchases/{pid}/clarify` | user | Request clarification |
| 30 | PATCH | `/orders/{id}/purchases/bulk-approve` | user | Bulk approve purchases |
| 31 | GET | `/orders/{id}/chat/messages` | user | Chat history |
| 32 | POST | `/orders/{id}/chat/messages` | user | Send message |
| 33 | PATCH | `/orders/{id}/chat/read` | user | Mark chat read |
| 34 | GET | `/chats` | user | List conversations |
| 35 | POST | `/orders/{id}/rating` | user | Rate worker |
| 36 | GET | `/orders/{id}/rating` | user | Get rating |
| 37 | GET | `/orders/{id}/invoice` | user | Get invoice |
| 38 | POST | `/orders/{id}/payment` | user | Confirm payment |
| 39 | GET | `/orders/{id}/invoice/pdf` | user | Download invoice PDF |
| 40 | GET | `/knowledge/articles` | any | List articles |
| 41 | GET | `/knowledge/articles/{id}` | any | Article detail |
| 42 | GET | `/knowledge/faq` | any | List FAQ |
| 43 | GET | `/notifications` | auth | List notifications |
| 44 | PATCH | `/notifications/{id}/read` | auth | Mark notification read |
| 45 | PATCH | `/notifications/read-all` | auth | Mark all read |

### Part D β€” Worker Endpoints

| # | Method | Endpoint | Role | Description |
|---|---|---|---|---|
| 46 | GET | `/worker/profile` | worker | Get worker profile |
| 47 | PUT | `/worker/profile` | worker | Update worker profile |
| 48 | PUT | `/worker/profile/cover-photo` | worker | Upload cover photo |
| 49 | POST | `/worker/profile/verification` | worker | Submit verification docs |
| 50 | GET | `/worker/profile/verification` | worker | Get verification status |
| 51 | GET | `/worker/home` | worker | Worker home dashboard |
| 52 | PATCH | `/worker/availability` | worker | Toggle availability |
| 53 | GET | `/worker/orders/incoming` | worker | List incoming orders |
| 54 | GET | `/worker/orders/incoming/{id}` | worker | Incoming order detail |
| 55 | POST | `/worker/orders/{id}/accept` | worker | Accept order |
| 56 | POST | `/worker/orders/{id}/reject` | worker | Reject order |
| 57 | GET | `/worker/orders` | worker | List all worker orders |
| 58 | GET | `/worker/orders/{id}` | worker | Order detail (worker view) |
| 59 | PATCH | `/worker/orders/{id}/status` | worker | Update order status |
| 60 | POST | `/worker/orders/{id}/generate-invoice` | worker | Generate invoice |
| 61 | POST | `/worker/orders/{id}/purchases` | worker | Add purchase |
| 62 | POST | `/worker/orders/{id}/purchases/ai-process` | worker | AI process raw input |
| 63 | POST | `/worker/orders/{id}/purchases/receipt-scan` | worker | Scan receipt (OCR + AI) |
| 64 | PUT | `/worker/orders/{id}/purchases/{pid}` | worker | Edit purchase |
| 65 | DELETE | `/worker/orders/{id}/purchases/{pid}` | worker | Delete purchase |
| 66 | POST | `/worker/orders/{id}/purchases/{pid}/submit` | worker | Submit for approval |
| 67 | POST | `/worker/orders/{id}/purchases/bulk-submit` | worker | Bulk submit purchases |
| 68 | PATCH | `/worker/orders/{id}/purchases/{pid}/clarify-response` | worker | Respond to clarification |
| 69 | GET | `/worker/orders/{id}/chat/messages` | worker | Chat history |
| 70 | POST | `/worker/orders/{id}/chat/messages` | worker | Send message |
| 71 | PATCH | `/worker/orders/{id}/chat/read` | worker | Mark chat read |
| 72 | GET | `/worker/chats` | worker | List conversations |
| 73 | POST | `/worker/orders/{id}/customer-rating` | worker | Rate customer |
| 74 | GET | `/worker/orders/{id}/customer-rating` | worker | Get customer rating |
| 75 | GET | `/worker/history` | worker | Order history |
| 76 | GET | `/worker/statistics` | worker | Performance statistics |
| 77 | GET | `/worker/wallet` | worker | Wallet balance |
| 78 | GET | `/worker/wallet/transactions` | worker | Transaction history |
| 79 | POST | `/worker/wallet/withdraw` | worker | Request withdrawal |
| 80 | PUT | `/worker/location` | worker | Update location |

### Part E β€” WebSocket Channels

| # | Protocol | Endpoint | Role | Description |
|---|---|---|---|---|
| 81 | WSS | `/ws/tracking/{order_id}` | auth | Real-time tracking |
| 82 | WSS | `/ws/chat/{order_id}` | auth | Real-time chat |

---

### πŸ“Š Totals

| Category | Count |
|---|---|
| Authentication | 6 |
| User Profile | 4 |
| User (Customer) Endpoints | 35 |
| Worker Endpoints | 35 |
| WebSocket Channels | 2 |
| **Grand Total** | **82** |

---

> **πŸ“Œ Document Version:** 1.0.0 | **Last Updated:** 2026-05-30 | **Total REST Endpoints:** 80 | **Total WebSocket Channels:** 2 | **Database Tables:** 24 | **Architecture:** Single Backend with RBAC via JWT