amp-rust 0.0.3

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

/// Sets up a mock for the GET /changelog endpoint.
///
/// This mock returns a sample changelog with version 0.1.0.
///
/// # Examples
/// ```
/// # use httpmock::prelude::*;
/// # use amp_rs::mocks::mock_get_changelog;
/// let server = MockServer::start();
/// mock_get_changelog(&server);
///
/// // Now requests to /changelog will return the mocked response
/// ```
pub fn mock_get_changelog(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/changelog");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "0.1.0": {
                    "added": [
                        "Initial release"
                    ]
                }
            }));
    });
}

/// # Panics
/// Panics if the request body cannot be parsed as JSON
pub fn mock_create_asset_assignments(server: &MockServer) {
    use serde_json::Value;

    server.mock(|when, then| {
        when.method(POST)
            .path("/assets/mock_asset_uuid/assignments/create")
            .header("content-type", "application/json")
            // Custom matcher to validate the request structure and data types
            .matches(|req| {
                // Parse the request body
                let body: Result<Value, _> = serde_json::from_slice(req.body.as_ref().unwrap());
                match body {
                    Ok(json) => {
                        // Validate that the request is wrapped in an "assignments" array
                        if let Some(assignments) = json.get("assignments") {
                            if let Some(assignments_array) = assignments.as_array() {
                                // Allow any number of assignments (1 or more)
                                if !assignments_array.is_empty() {
                                    // Validate each assignment
                                    for assignment in assignments_array {
                                        let has_registered_user = assignment
                                            .get("registered_user")
                                            .and_then(serde_json::Value::as_i64)
                                            .is_some();
                                        let has_amount = assignment
                                            .get("amount")
                                            .and_then(serde_json::Value::as_i64)
                                            .is_some();
                                        let vesting_timestamp_valid = assignment
                                            .get("vesting_timestamp")
                                            .is_none_or(|v| v.is_null() || v.is_i64()); // Optional field
                                        let ready_for_distribution_valid = assignment
                                            .get("ready_for_distribution")
                                            .is_none_or(serde_json::Value::is_boolean); // Optional field with default

                                        if !(has_registered_user
                                            && has_amount
                                            && vesting_timestamp_valid
                                            && ready_for_distribution_valid)
                                        {
                                            return false;
                                        }
                                    }
                                    return true;
                                }
                            }
                        }
                        false
                    }
                    Err(_) => false,
                }
            });
        then.status(200)
            .header("content-type", "application/json")
            // Response with single assignment for basic testing
            .json_body(json!([{
              "id": 10,
              "registered_user": 13,
              "amount": 100,
              "receiving_address": null,
              "distribution_uuid": null,
              "ready_for_distribution": true,
              "vesting_datetime": null,
              "vesting_timestamp": null,
              "has_vested": true,
              "is_distributed": false,
              "creator": 1,
              "GAID": "GA3DS3emT12zDF4RGywBvJqZfhefNp",
              "investor": 13
            }]));
    });
}

/// # Panics
/// Panics if the request body cannot be parsed as JSON
pub fn mock_create_asset_assignments_multiple(server: &MockServer) {
    use serde_json::Value;

    // First assignment request (amount: 100, user: 13)
    server.mock(|when, then| {
        when.method(POST)
            .path("/assets/mock_asset_uuid/assignments/create")
            .header("content-type", "application/json")
            .matches(|req| {
                let body: Result<Value, _> = serde_json::from_slice(req.body.as_ref().unwrap());
                body.is_ok_and(|json| {
                    json.get("assignments")
                        .and_then(serde_json::Value::as_array)
                        .is_some_and(|assignments| {
                            assignments.len() == 1
                                && assignments[0]
                                    .get("amount")
                                    .and_then(serde_json::Value::as_i64)
                                    == Some(100)
                        })
                })
            });
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!([
                {
                    "id": 10,
                    "registered_user": 13,
                    "amount": 100,
                    "receiving_address": null,
                    "distribution_uuid": null,
                    "ready_for_distribution": true,
                    "vesting_datetime": null,
                    "vesting_timestamp": null,
                    "has_vested": true,
                    "is_distributed": false,
                    "creator": 1,
                    "GAID": "GA3DS3emT12zDF4RGywBvJqZfhefNp",
                    "investor": 13
                }
            ]));
    });

    // Second assignment request (amount: 200, user: 14)
    server.mock(|when, then| {
        when.method(POST)
            .path("/assets/mock_asset_uuid/assignments/create")
            .header("content-type", "application/json")
            .matches(|req| {
                let body: Result<Value, _> = serde_json::from_slice(req.body.as_ref().unwrap());
                body.is_ok_and(|json| {
                    json.get("assignments")
                        .and_then(serde_json::Value::as_array)
                        .is_some_and(|assignments| {
                            assignments.len() == 1
                                && assignments[0]
                                    .get("amount")
                                    .and_then(serde_json::Value::as_i64)
                                    == Some(200)
                        })
                })
            });
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!([
                {
                    "id": 11,
                    "registered_user": 14,
                    "amount": 200,
                    "receiving_address": null,
                    "distribution_uuid": null,
                    "ready_for_distribution": true,
                    "vesting_datetime": null,
                    "vesting_timestamp": null,
                    "has_vested": true,
                    "is_distributed": false,
                    "creator": 1,
                    "GAID": "GA4DS3emT12zDF4RGywBvJqZfhefNp",
                    "investor": 14
                }
            ]));
    });
}

pub fn mock_broadcast_transaction(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST).path("/tx/broadcast");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "txid": "mock_txid",
                "hex": "mock_tx_hex"
            }));
    });
}

pub fn mock_get_broadcast_status(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/tx/broadcast/mock_txid");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "txid": "mock_txid",
                "hex": "mock_tx_hex"
            }));
    });
}

pub fn mock_remove_asset_from_group(server: &MockServer) {
    server.mock(|when, then| {
        when.method(DELETE)
            .path("/asset_groups/1/assets/mock_asset_uuid");
        then.status(200);
    });
}

pub fn mock_get_managers(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/managers");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!([{
                "id": 1,
                "username": "mock_manager",
                "is_locked": false,
                "assets": []
            }]));
    });
}

pub fn mock_create_manager(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST).path("/managers/create");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 2,
                "username": "test_manager",
                "is_locked": false,
                "assets": []
            }));
    });
}

/// Sets up a mock for the POST `/user/obtain_token` endpoint.
///
/// This mock returns a successful token response with `"mock_token"`.
///
/// # Examples
/// ```
/// # use httpmock::prelude::*;
/// # use amp_rs::mocks::mock_obtain_token;
/// let server = MockServer::start();
/// mock_obtain_token(&server);
///
/// // Now token requests will return the mocked token
/// ```
pub fn mock_obtain_token(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST).path("/user/obtain_token");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "token": "mock_token"
            }));
    });
}

pub fn mock_refresh_token(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST)
            .path("/user/refresh_token")
            .header("authorization", "token mock_token");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "token": "mock_refreshed_token"
            }));
    });
}

pub fn mock_obtain_token_with_rate_limiting(server: &MockServer, retry_after_seconds: u64) {
    server.mock(|when, then| {
        when.method(POST)
            .path("/user/obtain_token")
            .header("content-type", "application/json");
        then.status(429)
            .header("retry-after", retry_after_seconds.to_string())
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Too Many Requests"
            }));
    });
}

pub fn mock_obtain_token_server_error(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST)
            .path("/user/obtain_token")
            .header("content-type", "application/json");
        then.status(500)
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Internal Server Error"
            }));
    });
}

pub fn mock_refresh_token_failure(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST).path("/user/refresh_token");
        then.status(401)
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Invalid token"
            }));
    });
}

pub fn mock_get_gaid_address(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/gaids/GAbYScu6jkWUND2jo3L4KJxyvo55d/address");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "address": "mock_address"
            }));
    });
}

pub fn mock_validate_gaid(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/gaids/GAbYScu6jkWUND2jo3L4KJxyvo55d/validate");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "is_valid": true
            }));
    });
}

pub fn mock_get_categories(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/categories");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!([{
                "id": 1,
                "name": "Mock Category",
                "description": "A mock category",
                "registered_users": [],
                "assets": []
            }]));
    });
}

pub fn mock_add_category(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST).path("/categories/add");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 2,
                "name": "Test Category",
                "description": "Test category description",
                "registered_users": [],
                "assets": []
            }));
    });
}

pub fn mock_add_registered_user(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST).path("/registered_users/add");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 2,
                "name": "Test User",
                "gaid": null,
                "is_company": false,
                "authorization_url": "https://example.com/auth_new",
                "categories": [],
                "creator": 1
            }));
    });
}

pub fn mock_delete_asset(server: &MockServer) {
    server.mock(|when, then| {
        when.method(DELETE)
            .path("/assets/new_mock_asset_uuid/delete");
        then.status(200);
    });
}

pub fn mock_get_registered_users(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/registered_users");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!([{
                "id": 1,
                "name": "Mock User",
                "GAID": "mock_gaid",
                "is_company": false,
                "authorization_url": "https://example.com/auth",
                "categories": [],
                "creator": 1
            }]));
    });
}

pub fn mock_get_registered_user(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/registered_users/1");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 1,
                "name": "Mock User",
                "gaid": "mock_gaid",
                "is_company": false,
                "authorization_url": "https://example.com/auth",
                "categories": [],
                "creator": 1
            }));
    });
}

pub fn mock_edit_asset(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/assets/mock_asset_uuid/edit")
            .header("content-type", "application/json");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "name": "Mock Asset",
                "asset_uuid": "mock_asset_uuid",
                "issuer": 1,
                "asset_id": "mock_asset_id",
                "reissuance_token_id": null,
                "requirements": [],
                "ticker": "MOCK",
                "precision": 8,
                "domain": "mock.com",
                "pubkey": "mock_pubkey",
                "is_registered": true,
                "is_authorized": true,
                "is_locked": false,
                "issuer_authorization_endpoint": "https://example.com/authorize",
                "transfer_restricted": true
            }));
    });
}

/// Sets up a mock for the POST /assets/issue endpoint.
///
/// This mock returns a successful asset issuance response with mock data.
///
/// # Examples
/// ```
/// # use httpmock::prelude::*;
/// # use amp_rs::mocks::mock_issue_asset;
/// let server = MockServer::start();
/// mock_issue_asset(&server);
///
/// // Now asset issuance requests will return the mocked response
/// ```
pub fn mock_issue_asset(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST).path("/assets/issue");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "name": "Test Asset",
                "amount": 1000,
                "destination_address": "destination_address",
                "domain": "example.com",
                "ticker": "TSTA",
                "pubkey": "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
                "is_confidential": true,
                "is_reissuable": false,
                "reissuance_amount": 0,
                "reissuance_address": "reissuance_address",
                "asset_id": "mock_asset_id",
                "reissuance_token_id": null,
                "asset_uuid": "new_mock_asset_uuid",
                "txid": "mock_txid",
                "vin": 0,
                "asset_vout": 0,
                "reissuance_vout": null,
                "issuer_authorization_endpoint": null,
                "transfer_restricted": true,
                "issuance_assetblinder": "mock_blinder",
                "issuance_tokenblinder": null
            }));
    });
}

/// Sets up a mock for the GET /assets endpoint.
///
/// This mock returns a list containing one sample asset with mock data.
///
/// # Examples
/// ```
/// # use httpmock::prelude::*;
/// # use amp_rs::mocks::mock_get_assets;
/// let server = MockServer::start();
/// mock_get_assets(&server);
///
/// // Now requests to /assets will return the mocked asset list
/// ```
pub fn mock_get_assets(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/assets");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!([{
                "name": "Mock Asset",
                "asset_uuid": "mock_asset_uuid",
                "issuer": 1,
                "asset_id": "mock_asset_id",
                "reissuance_token_id": null,
                "requirements": [],
                "ticker": "MOCK",
                "precision": 8,
                "domain": "mock.com",
                "pubkey": "mock_pubkey",
                "is_registered": true,
                "is_authorized": true,
                "is_locked": false,
                "issuer_authorization_endpoint": null,
                "transfer_restricted": true
            }]));
    });
}

pub fn mock_get_asset(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/assets/mock_asset_uuid");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "name": "Mock Asset",
                "asset_uuid": "mock_asset_uuid",
                "issuer": 1,
                "asset_id": "mock_asset_id",
                "reissuance_token_id": null,
                "requirements": [],
                "ticker": "MOCK",
                "precision": 8,
                "domain": "mock.com",
                "pubkey": "mock_pubkey",
                "is_registered": true,
                "is_authorized": true,
                "is_locked": false,
                "issuer_authorization_endpoint": "https://example.com/authorize",
                "transfer_restricted": true
            }));
    });
}

pub fn mock_get_manager(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/managers/1");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 1,
                "username": "mock_manager",
                "is_locked": false,
                "assets": ["asset_uuid_1", "asset_uuid_2"]
            }));
    });
}

pub fn mock_manager_remove_asset(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST)
            .path("/managers/1/assets/asset_uuid_1/remove");
        then.status(200);
    });

    server.mock(|when, then| {
        when.method(POST)
            .path("/managers/1/assets/asset_uuid_2/remove");
        then.status(200);
    });
}

pub fn mock_get_current_manager_raw(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/managers/me");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 1,
                "username": "current_manager",
                "is_locked": false,
                "assets": ["asset_uuid_1"]
            }));
    });
}

pub fn mock_lock_manager(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT).path("/managers/1/lock");
        then.status(200);
    });
}

pub fn mock_lock_manager_invalid_id(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT).path("/managers/999_999/lock");
        then.status(404)
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Manager not found"
            }));
    });
}

pub fn mock_lock_manager_server_error(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT).path("/managers/1/lock");
        then.status(500)
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Internal server error"
            }));
    });
}

pub fn mock_add_asset_to_manager(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/managers/1/assets/mock_asset_uuid/add");
        then.status(200);
    });
}

pub fn mock_add_asset_to_manager_invalid_manager_id(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/managers/999_999/assets/mock_asset_uuid/add");
        then.status(404)
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Manager not found"
            }));
    });
}

pub fn mock_add_asset_to_manager_invalid_asset_uuid(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/managers/1/assets/invalid_asset_uuid/add");
        then.status(404)
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Asset not found"
            }));
    });
}

pub fn mock_add_asset_to_manager_server_error(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/managers/1/assets/mock_asset_uuid/add");
        then.status(500)
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Internal server error"
            }));
    });
}

pub fn mock_get_asset_assignment(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/assets/mock_asset_uuid/assignments/10");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 10,
                "registered_user": 13,
                "amount": 100,
                "receiving_address": null,
                "distribution_uuid": null,
                "ready_for_distribution": true,
                "vesting_datetime": null,
                "vesting_timestamp": null,
                "has_vested": true,
                "is_distributed": false,
                "creator": 1,
                "GAID": "GA3DS3emT12zDF4RGywBvJqZfhefNp",
                "investor": 13
            }));
    });
}

pub fn mock_unlock_manager(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT).path("/managers/1/unlock");
        then.status(200);
    });
}

pub fn mock_add_asset_treasury_addresses(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST)
            .path("/assets/mock_asset_uuid/treasury-addresses/add")
            .header("content-type", "application/json");
        then.status(200);
    });
}

pub fn mock_get_asset_treasury_addresses(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/assets/mock_asset_uuid/treasury-addresses");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!([
                "vjU2i2EM2viGEzSywpStMPkTX9U9QSDsLSN63kJJYVpxKJZuxaph8v5r5Jf11aqnfBVdjSbrvcJ2pw26",
                "vjU2i2EM2viGEzSywpStMPkTX9U9QSDsLSN63kJJYVpxKJZuxaph8v5r5Jf11aqnfBVdjSbrvcJ2pw27"
            ]));
    });
}

pub fn mock_delete_asset_assignment(server: &MockServer) {
    server.mock(|when, then| {
        when.method(DELETE)
            .path("/assets/mock_asset_uuid/assignments/10/delete");
        then.status(200);
    });
}

pub fn mock_lock_asset_assignment(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/assets/mock_asset_uuid/assignments/10/lock");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 10,
                "registered_user": 13,
                "amount": 100,
                "receiving_address": null,
                "distribution_uuid": null,
                "ready_for_distribution": true,
                "vesting_datetime": null,
                "vesting_timestamp": null,
                "has_vested": true,
                "is_distributed": false,
                "creator": 1,
                "GAID": "GA3DS3emT12zDF4RGywBvJqZfhefNp",
                "investor": 13
            }));
    });
}

pub fn mock_unlock_asset_assignment(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/assets/mock_asset_uuid/assignments/10/unlock");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 10,
                "registered_user": 13,
                "amount": 100,
                "receiving_address": null,
                "distribution_uuid": null,
                "ready_for_distribution": true,
                "vesting_datetime": null,
                "vesting_timestamp": null,
                "has_vested": true,
                "is_distributed": false,
                "creator": 1,
                "GAID": "GA3DS3emT12zDF4RGywBvJqZfhefNp",
                "investor": 13
            }));
    });
}
pub fn mock_lock_asset(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT).path("/assets/mock_asset_uuid/lock");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "asset_uuid": "mock_asset_uuid",
                "name": "Mock Asset",
                "issuer": 1,
                "asset_id": "mock_asset_id",
                "reissuance_token_id": "mock_reissuance_token_id",
                "requirements": [],
                "ticker": "MOCK",
                "precision": 8,
                "domain": "example.com",
                "pubkey": "mock_pubkey",
                "is_registered": true,
                "is_authorized": true,
                "is_locked": true,
                "issuer_authorization_endpoint": "https://example.com/authorize",
                "transfer_restricted": true
            }));
    });
}

pub fn mock_unlock_asset(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT).path("/assets/mock_asset_uuid/unlock");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "asset_uuid": "mock_asset_uuid",
                "name": "Mock Asset",
                "issuer": 1,
                "asset_id": "mock_asset_id",
                "reissuance_token_id": "mock_reissuance_token_id",
                "requirements": [],
                "ticker": "MOCK",
                "precision": 8,
                "domain": "example.com",
                "pubkey": "mock_pubkey",
                "is_registered": true,
                "is_authorized": true,
                "is_locked": false,
                "issuer_authorization_endpoint": "https://example.com/authorize",
                "transfer_restricted": true
            }));
    });
}

pub fn mock_edit_registered_user(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/registered_users/1/edit")
            .header("content-type", "application/json");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 1,
                "name": "Updated User Name",
                "GAID": "mock_gaid",
                "is_company": false,
                "categories": [],
                "creator": 1
            }));
    });
}

pub fn mock_get_registered_user_summary(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/registered_users/1/summary");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "asset_uuid": "mock_asset_uuid",
                "asset_id": "mock_asset_id",
                "assignments": [{
                    "id": 1,
                    "registered_user": 1,
                    "amount": 1000,
                    "receiving_address": null,
                    "distribution_uuid": null,
                    "ready_for_distribution": true,
                    "vesting_datetime": null,
                    "vesting_timestamp": null,
                    "has_vested": true,
                    "is_distributed": false,
                    "creator": 1,
                    "GAID": "mock_gaid",
                    "investor": 1
                }],
                "assignments_sum": 1000,
                "distributions": [],
                "distributions_sum": 0,
                "balance": 1000
            }));
    });
}

pub fn mock_get_registered_user_gaids(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/registered_users/1/gaids");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!([
                "GA44YYwPM8vuRMmjFL8i5kSqXhoTW2",
                "GAbYScu6jkWUND2jo3L4KJxyvo55d"
            ]));
    });
}

pub fn mock_add_gaid_to_registered_user(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST)
            .path("/registered_users/1/gaids/add")
            .header("content-type", "application/json");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({}));
    });
}

pub fn mock_set_default_gaid_for_registered_user(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST)
            .path("/registered_users/1/gaids/set-default")
            .header("content-type", "application/json");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({}));
    });
}

pub fn mock_get_gaid_registered_user(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/gaids/GA44YYwPM8vuRMmjFL8i5kSqXhoTW2/registered_user");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 1,
                "name": "Mock User",
                "GAID": "GA44YYwPM8vuRMmjFL8i5kSqXhoTW2",
                "is_company": false,
                "categories": [],
                "creator": 1
            }));
    });
}

pub fn mock_get_gaid_balance(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/gaids/GA44YYwPM8vuRMmjFL8i5kSqXhoTW2/balance");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!([
                {
                    "asset_uuid": "716cb816-6cc7-469d-a41f-f4ed1c0d2dce",
                    "asset_id": "5b72739ee4097c32e9eb2fa5f43fd51b35e13323e58c511d6da91adbc4ac24ca",
                    "balance": 0
                },
                {
                    "asset_uuid": "5fd36bad-f0af-4b13-a0b5-fb1a91b751a4",
                    "asset_id": "ae4bfd3b5dc9d6d1dc77e1c8840fa06b4e9abeabec024cf1d9efb96935757be0",
                    "balance": 0
                }
            ]));
    });
}

pub fn mock_get_gaid_asset_balance(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/gaids/GA44YYwPM8vuRMmjFL8i5kSqXhoTW2/balance/mock_asset_uuid");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "asset_uuid": "mock_asset_uuid",
                "asset_id": "mock_asset_id",
                "balance": 100_000
            }));
    });
}

pub fn mock_add_categories_to_registered_user(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/registered_users/1/categories/add")
            .header("content-type", "application/json");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({}));
    });
}

pub fn mock_remove_categories_from_registered_user(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/registered_users/1/categories/delete")
            .header("content-type", "application/json");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({}));
    });
}

pub fn mock_get_asset_memo(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET).path("/assets/mock_asset_uuid/memo");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!("Sample memo for mock asset"));
    });
}

pub fn mock_set_asset_memo(server: &MockServer) {
    server.mock(|when, then| {
        when.method(POST)
            .path("/assets/mock_asset_uuid/memo/set")
            .header("content-type", "application/json");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({}));
    });
}

pub fn mock_add_asset_to_category(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/categories/1/assets/mock_asset_uuid/add");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 1,
                "name": "Mock Category",
                "description": "A mock category",
                "registered_users": [],
                "assets": ["mock_asset_uuid"]
            }));
    });
}

pub fn mock_remove_asset_from_category(server: &MockServer) {
    server.mock(|when, then| {
        when.method(PUT)
            .path("/categories/1/assets/mock_asset_uuid/remove");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "id": 1,
                "name": "Mock Category",
                "description": "A mock category",
                "registered_users": [],
                "assets": []
            }));
    });
}
pub fn mock_get_asset_assignment_invalid_asset_uuid(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/assets/invalid_asset_uuid/assignments/10");
        then.status(404)
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Asset not found"
            }));
    });
}

pub fn mock_get_asset_assignment_invalid_assignment_id(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/assets/mock_asset_uuid/assignments/999_999");
        then.status(404)
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Assignment not found"
            }));
    });
}

pub fn mock_get_asset_assignment_non_existent(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/assets/non_existent_asset/assignments/non_existent_assignment");
        then.status(404)
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Assignment not found"
            }));
    });
}

pub fn mock_get_asset_assignment_server_error(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/assets/mock_asset_uuid/assignments/10");
        then.status(500)
            .header("content-type", "application/json")
            .json_body(json!({
                "error": "Internal server error"
            }));
    });
}
pub fn mock_get_asset_distribution(server: &MockServer) {
    server.mock(|when, then| {
        when.method(GET)
            .path("/assets/mock_asset_uuid/distributions/mock_distribution_uuid");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({
                "distribution_uuid": "mock_distribution_uuid",
                "distribution_status": "CONFIRMED",
                "transactions": [
                    {
                        "txid": "7ceabde8d7c1596b8b4af27286681dbde9c1551614b9788b6f84b9a3789d3184",
                        "transaction_status": "CONFIRMED",
                        "included_blockheight": 2_146_947,
                        "confirmed_datetime": "2025-10-22T20:45:13.879485Z",
                        "assignments": [
                            {
                                "registered_user": 1936,
                                "amount": 1,
                                "vout": 2
                            }
                        ]
                    }
                ]
            }));
    });
}