delopay 0.20.0

Official Rust SDK for the DeloPay payments API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
//! Product catalogue models: a shop's products, their prices, categories,
//! add-on groups and bundles, and how the catalogue compares with the
//! connected accounts it is tied to.
//!
//! Every price route answers with the whole [`ProductResponse`]: a price means
//! something only beside its siblings, so the price that was touched is found
//! in the product's `prices`.

use serde::{Deserialize, Serialize};
use serde_json::Value;

use crate::core::models::common::Currency;

/// What a catalogue product is sold as.
///
/// `one_time` and `recurring` are sold on their own. An `addon` is an optional
/// extra chosen with a one-time product through one of its selection groups; a
/// `bundle` is a named set of one-time products sold as one offer.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProductKind {
    /// Sold once.
    OneTime,
    /// Billed on a schedule.
    Recurring,
    /// An optional extra chosen with a one-time product.
    Addon,
    /// A named set of one-time products sold as one offer.
    Bundle,
    /// A kind this SDK version does not know yet. Never send it.
    #[serde(other)]
    Unknown,
}

/// Whether a product, a price or a category is still in use.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProductStatus {
    /// On sale, or able to take products.
    Active,
    /// Kept and readable, but withdrawn.
    Archived,
    /// A status this SDK version does not know yet. Never send it.
    #[serde(other)]
    Unknown,
}

impl ProductStatus {
    /// The status as the API spells it, e.g. for a query parameter.
    pub fn as_str(self) -> &'static str {
        match self {
            ProductStatus::Active => "active",
            ProductStatus::Archived => "archived",
            ProductStatus::Unknown => "unknown",
        }
    }
}

/// The unit a recurring price bills in, and the unit a trial is measured in.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProductPriceInterval {
    /// Days.
    Day,
    /// Weeks.
    Week,
    /// Months.
    Month,
    /// Years.
    Year,
    /// An interval this SDK version does not know yet. Never send it.
    #[serde(other)]
    Unknown,
}

/// Whether a price's amount includes tax or has it added on top by the billing
/// processor.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProductPriceTaxBehavior {
    /// The amount is what the buyer pays. Every price is this unless created
    /// otherwise.
    Inclusive,
    /// The billing processor adds tax on top of the amount: show it as "plus
    /// tax", never as what the buyer pays. Only a recurring price billed by
    /// Creem can be this, and only where the deployment allows it.
    Exclusive,
    /// A mode this SDK version does not know yet. Never send it.
    #[serde(other)]
    Unknown,
}

/// How a bundle is priced.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum BundlePricing {
    /// At the bundle's own prices, listing every component at no charge.
    Fixed,
    /// At the sum of its components' active default prices, read when the
    /// payment is created. The bundle then has no prices of its own.
    Sum,
    /// A pricing mode this SDK version does not know yet. Never send it.
    #[serde(other)]
    Unknown,
}

/// What to do at one connected account when a product is deleted or archived
/// there.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProviderArchiveAction {
    /// Archive the provider's product and deactivate its prices.
    Archive,
    /// Deactivate the provider's billing plans.
    DeactivatePlans,
    /// Leave the provider's product as it is.
    Keep,
    /// An action this SDK version does not know yet. Never send it.
    #[serde(other)]
    Unknown,
}

/// Whether a name is the product's current name or another name it goes by.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProductAliasKind {
    /// The product's current name.
    Name,
    /// Another name the product goes by.
    Alias,
    /// A kind this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// How a connected account's product or price was tied to a catalogue
/// product.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProductMappingMode {
    /// Accepted from the connected account's own listing.
    MapExisting,
    /// Typed by hand; the ids were not checked against the account.
    ManualId,
    /// A mode this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// What a product was resolved by.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProductMatch {
    /// The product's current name.
    Name,
    /// Another name the product goes by.
    Alias,
    /// A connector's id for the product.
    ConnectorProduct,
    /// A connector's id for one of the product's prices.
    ConnectorPrice,
    /// A match this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// Whether one recurring price can start a subscription on the shop's billing
/// processor account, in the environment the account is in now.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PriceBillingState {
    /// The account holds a reference read from the account itself.
    Ready,
    /// The only reference was typed by hand.
    Unverified,
    /// The account holds a reference only for its other environment.
    OtherEnvironment,
    /// The account holds no reference for the price.
    NeedsReference,
    /// A state this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// How a provider item relates to the catalogue right now.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProductImportClassification {
    /// Not in the catalogue yet.
    New,
    /// In the catalogue, with prices the catalogue does not have.
    Changed,
    /// In the catalogue as the provider has it.
    Unchanged,
    /// Tied to a catalogue product, but no longer offered by the provider.
    Unavailable,
    /// Cannot be imported; `note` says why.
    Conflicting,
    /// A classification this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// How one provider price relates to the catalogue.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProductImportPriceState {
    /// Not in the catalogue yet.
    New,
    /// Already referenced by a catalogue price.
    Known,
    /// Referenced by a catalogue price with other terms.
    Changed,
    /// A state this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// How a connected account's copy of a product compares with the catalogue.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProviderSyncStatus {
    /// The provider's copy matches the catalogue.
    InSync,
    /// The provider's copy differs; see `differences`.
    ChangedAtProvider,
    /// The provider no longer has the product.
    MissingAtProvider,
    /// The provider could not be read. Never read as in sync.
    Unknown,
    /// The product is not tied to the account.
    NotLinked,
    /// A status this SDK version does not know yet.
    #[serde(other)]
    Unrecognized,
}

/// A field compared between the catalogue and the provider.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProviderSyncField {
    /// The product's name.
    Name,
    /// The product's description.
    Description,
    /// The product's image.
    ImageUrl,
    /// Whether the product is active.
    Active,
    /// The provider price the product defaults to: the catalogue side is the
    /// provider price id the catalogue's default price is tied to, the
    /// provider side its current default.
    DefaultPrice,
    /// A price's amount, currency or interval.
    PriceTerms,
    /// Whether a price is active.
    PriceActive,
    /// A price the catalogue references is missing at the provider.
    PriceMissing,
    /// A catalogue price that is not at the provider.
    PriceNotAtProvider,
    /// A provider price that is not in the catalogue.
    PriceOnlyAtProvider,
    /// A field this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// What a push to the provider does about one difference.
///
/// `replace_price` and `deactivate_price` leave existing subscriptions at the
/// provider on the old price; they are never migrated.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProviderPushAction {
    /// Update the provider's product.
    UpdateProduct,
    /// Create a price at the provider.
    CreatePrice,
    /// Create a new provider price and deactivate the old one.
    ReplacePrice,
    /// Activate a provider price.
    ActivatePrice,
    /// Deactivate a provider price.
    DeactivatePrice,
    /// An action this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// How a provider can be cleaned up when a product is deleted.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProviderArchiveMode {
    /// The provider's product is archived and its prices deactivated.
    Archive,
    /// The billing plans are deactivated; the provider has no product delete.
    DeactivatePlans,
    /// Nothing can be done through the provider's API.
    #[serde(rename = "none")]
    NoAction,
    /// A mode this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// What an archive did at one connected account.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProviderArchiveStatus {
    /// The action was carried out.
    Done,
    /// `keep` was asked for.
    Kept,
    /// The provider cannot do the action; see `reason`.
    Unsupported,
    /// The provider could not be read or refused; see `reason`.
    Failed,
    /// A status this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// Why the catalogue cannot work with a connected account right now.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProviderUnavailableReason {
    /// The account holds no credentials for the environment it is in.
    NoCredentialsForEnvironment,
    /// A reason this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// A connected account's environment.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ProviderEnvironment {
    /// Live.
    Live,
    /// Sandbox.
    Test,
    /// An environment this SDK version does not know yet.
    #[serde(other)]
    Unknown,
}

/// A price as the catalogue reports it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductPriceResponse {
    /// Price ID.
    pub id: String,
    /// The product the price belongs to.
    pub product_id: String,
    /// The price's label.
    #[serde(default)]
    pub nickname: Option<String>,
    /// Minor units, in `currency`.
    pub amount: i64,
    /// Three-letter ISO 4217 currency code.
    pub currency: Currency,
    /// The unit a recurring price bills in; `None` for a one-time price.
    #[serde(default)]
    pub billing_interval: Option<ProductPriceInterval>,
    /// How many `billing_interval`s one billing period lasts.
    #[serde(default)]
    pub billing_interval_count: Option<i32>,
    /// The trial's length, in `trial_period_unit`s.
    #[serde(default)]
    pub trial_period: Option<i32>,
    /// The unit the trial is measured in.
    #[serde(default)]
    pub trial_period_unit: Option<ProductPriceInterval>,
    /// The price a checkout picks when none is named.
    pub is_default: bool,
    /// Whether the amount includes tax or has it added on top. `None` from an
    /// older API, where every price includes it.
    #[serde(default)]
    pub tax_behavior: Option<ProductPriceTaxBehavior>,
    /// Whether the price is still on sale.
    pub status: ProductStatus,
    /// Your own key-value data.
    #[serde(default)]
    pub metadata: Option<Value>,
    /// ISO 8601 creation timestamp.
    pub created_at: String,
    /// ISO 8601 last-modification timestamp.
    pub modified_at: String,
    /// When the price was archived.
    #[serde(default)]
    pub archived_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A name a product goes by.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductAliasResponse {
    /// Alias ID.
    pub id: String,
    /// The name.
    pub alias: String,
    /// Whether it is the current name or another name.
    pub kind: ProductAliasKind,
    /// ISO 8601 creation timestamp.
    pub created_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A connected account's product or price, tied to a catalogue product.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductConnectorReferenceResponse {
    /// Reference ID.
    pub id: String,
    /// The connector, e.g. `"stripe"`.
    pub connector: String,
    /// The connected account the ids belong to.
    pub merchant_connector_id: String,
    /// The connector's id for the product.
    pub connector_product_id: String,
    /// The connector's id for the price; `None` on a reference to the
    /// connector's product itself.
    #[serde(default)]
    pub connector_price_id: Option<String>,
    /// The catalogue price the connector's price stands for.
    #[serde(default)]
    pub price_id: Option<String>,
    /// What the connector calls the product or the price.
    #[serde(default)]
    pub display_name: Option<String>,
    /// How the reference was made.
    pub mapping_mode: ProductMappingMode,
    /// The environment the ids belong to: `true` for the account's sandbox,
    /// `false` for live. `None` when it was not recorded; such a reference
    /// stands for either environment.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// On a provider product sold both once and on a schedule and imported as
    /// two catalogue products: which of the two this product is. `None` when
    /// the reference stands for the whole provider product.
    #[serde(default)]
    pub product_kind: Option<ProductKind>,
    /// `pending` while archiving the provider's copy failed after the product
    /// was deleted; retry with `Products::provider_archive`. `None`
    /// otherwise.
    #[serde(default)]
    pub cleanup_status: Option<String>,
    /// Why the last clean-up attempt failed.
    #[serde(default)]
    pub cleanup_error: Option<String>,
    /// When the clean-up was last attempted (UTC, ISO 8601).
    #[serde(default)]
    pub cleanup_attempted_at: Option<String>,
    /// ISO 8601 creation timestamp.
    pub created_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// An add-on a group offers, with what it costs today.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct AddonGroupItemResponse {
    /// The add-on product.
    pub addon_product_id: String,
    /// The add-on's name.
    pub name: String,
    /// Whether the add-on is still on sale.
    pub status: ProductStatus,
    /// The add-on's active default price. `None` when it has none, in which
    /// case the add-on cannot be chosen.
    #[serde(default)]
    pub price: Option<ProductPriceResponse>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A group of optional extras a product offers.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct AddonGroupResponse {
    /// Group ID.
    pub id: String,
    /// The group's name.
    pub name: String,
    /// How many add-ons a buyer must choose; 0 makes the group optional.
    pub min_choices: i32,
    /// How many add-ons a buyer may choose.
    pub max_choices: i32,
    /// The add-ons the group offers, in order.
    #[serde(default)]
    pub items: Vec<AddonGroupItemResponse>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One component of a bundle.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BundleItemResponse {
    /// The component product.
    pub product_id: String,
    /// The component's name.
    pub name: String,
    /// Whether the component is still on sale.
    pub status: ProductStatus,
    /// How many of the component the bundle holds.
    pub quantity: i32,
    /// The component's active default price; `None` when it has none.
    #[serde(default)]
    pub price: Option<ProductPriceResponse>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A product as the catalogue reports it, prices and identity included.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductResponse {
    /// Product ID.
    pub id: String,
    /// The shop the product belongs to.
    pub profile_id: String,
    /// The product's current name.
    pub name: String,
    /// Free-form description.
    #[serde(default)]
    pub description: Option<String>,
    /// The product's image.
    #[serde(default)]
    pub image_url: Option<String>,
    /// What the product is sold as.
    pub kind: ProductKind,
    /// Whether the product is still on sale.
    pub status: ProductStatus,
    /// The product's prices, archived ones included.
    #[serde(default)]
    pub prices: Vec<ProductPriceResponse>,
    /// Every name, the current name included, oldest first.
    #[serde(default)]
    pub aliases: Vec<ProductAliasResponse>,
    /// Oldest first. A caller limited to some connected accounts sees only
    /// their references.
    #[serde(default)]
    pub connector_references: Vec<ProductConnectorReferenceResponse>,
    /// The optional extras the product offers, in order. Empty for a product
    /// that offers none, and always for an add-on or a bundle.
    #[serde(default)]
    pub addon_groups: Vec<AddonGroupResponse>,
    /// How a bundle is priced; `None` for every other kind.
    #[serde(default)]
    pub bundle_pricing: Option<BundlePricing>,
    /// What a bundle contains, in order; empty for every other kind.
    #[serde(default)]
    pub bundle_items: Vec<BundleItemResponse>,
    /// Your own key-value data.
    #[serde(default)]
    pub metadata: Option<Value>,
    /// ISO 8601 creation timestamp.
    pub created_at: String,
    /// ISO 8601 last-modification timestamp.
    pub modified_at: String,
    /// When the product was archived.
    #[serde(default)]
    pub archived_at: Option<String>,
    /// The shop category the product is filed under; `None` is
    /// uncategorized.
    #[serde(default)]
    pub category_id: Option<String>,
    /// Whether the buyer chooses the product's add-ons in the hosted
    /// checkout.
    #[serde(default)]
    pub buyer_chooses_addons: bool,
    /// The invoice tax category; `None` is `standard`.
    #[serde(default)]
    pub tax_category: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One page of a shop's catalogue, newest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductListResponse {
    /// The products on this page.
    #[serde(default)]
    pub data: Vec<ProductResponse>,
    /// How many products match the filter in total, across all pages.
    pub total_count: i64,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// An uploaded product image.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductImageUploadResponse {
    /// The hosted image. Save it as a product's `image_url`.
    pub image_url: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The product a name or a connector's id resolves to. Archived products
/// resolve too, so a payment that references one is still attributed.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductResolveResponse {
    /// What the product was resolved by.
    pub matched_by: ProductMatch,
    /// The price the connector's price stands for, when the product was
    /// resolved by a price reference that names one.
    #[serde(default)]
    pub price_id: Option<String>,
    /// The product.
    pub product: ProductResponse,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A product's sales in one currency and the refunds credited back to it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductSalesByCurrency {
    /// Three-letter ISO 4217 currency code.
    pub currency: String,
    /// Succeeded payments with at least one line of the product.
    pub payment_count: i64,
    /// Units sold.
    pub sold_quantity: i64,
    /// The product's line totals, minor units.
    pub sold_amount: i64,
    /// Units given back by succeeded refunds credited to the product's lines.
    pub refunded_quantity: i64,
    /// Minor units given back by those refunds.
    pub refunded_amount: i64,
    /// Units of refunds still in flight; not deducted from `net_quantity`.
    pub refund_pending_quantity: i64,
    /// Minor units of refunds still in flight; not deducted from
    /// `net_amount`.
    pub refund_pending_amount: i64,
    /// `sold_quantity - refunded_quantity`.
    pub net_quantity: i64,
    /// `sold_amount - refunded_amount`.
    pub net_amount: i64,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a product sold in a window, per currency.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductSalesResponse {
    /// The product.
    pub product_id: String,
    /// The shop.
    pub profile_id: String,
    /// Whether test payments were totalled.
    pub test_mode: bool,
    /// The window's start.
    pub start_time: String,
    /// The window's end.
    pub end_time: String,
    /// One entry per currency sold in; empty when nothing was sold.
    #[serde(default)]
    pub currencies: Vec<ProductSalesByCurrency>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The shop's billing processor account, as readiness was checked against it.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BillingAccountSummary {
    /// The connected account.
    pub merchant_connector_id: String,
    /// The connector, e.g. `"stripe"`.
    pub connector: String,
    /// The environment the account is in now: `true` for its sandbox.
    pub test_mode: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One recurring price and whether it can start a subscription.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PriceBillingReadiness {
    /// The product.
    pub product_id: String,
    /// The price.
    pub price_id: String,
    /// Whether the price can start a subscription.
    pub state: PriceBillingState,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Which active recurring prices can start a subscription on the shop's
/// billing processor account.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BillingReadinessResponse {
    /// The billing account checked; `None` when the shop has none.
    #[serde(default)]
    pub billing_account: Option<BillingAccountSummary>,
    /// Every active price of the requested recurring products. Unknown ids,
    /// one-time products and archived prices are left out.
    #[serde(default)]
    pub prices: Vec<PriceBillingReadiness>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A shop category.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductCategoryResponse {
    /// Category ID.
    pub id: String,
    /// The shop the category belongs to.
    pub profile_id: String,
    /// The category's name.
    pub name: String,
    /// Where the category sits in the shop's order, ascending.
    pub position: i32,
    /// `active`, or `archived`: kept with its products, but no product can be
    /// filed under it.
    pub status: ProductStatus,
    /// ISO 8601 creation timestamp.
    pub created_at: String,
    /// ISO 8601 last-modification timestamp.
    pub modified_at: String,
    /// When the category was archived.
    #[serde(default)]
    pub archived_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The shop's categories, in order.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductCategoryListResponse {
    /// The categories.
    #[serde(default)]
    pub data: Vec<ProductCategoryResponse>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// How one provider price relates to the catalogue.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductImportPricePreview {
    /// The provider's id for the price.
    pub connector_price_id: String,
    /// Minor units, in `currency`.
    pub amount: i64,
    /// Three-letter ISO 4217 currency code.
    pub currency: Currency,
    /// The billing unit; `None` for a one-time price.
    #[serde(default)]
    pub interval: Option<ProductPriceInterval>,
    /// How many `interval`s one billing period lasts.
    #[serde(default)]
    pub interval_count: Option<i32>,
    /// How the price relates to the catalogue.
    pub state: ProductImportPriceState,
    /// The catalogue price that references it, when one does.
    #[serde(default)]
    pub price_id: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// How one provider item relates to the catalogue.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductImportItemPreview {
    /// Identifies this item and what the preview says about it.
    pub key: String,
    /// The provider's id for the product.
    pub connector_product_id: String,
    /// The provider sells the item both once and on a schedule; an apply's
    /// `decisions` can split it, keep it recurring only, or skip it.
    pub mixed: bool,
    /// The item's name.
    pub name: String,
    /// The item's description.
    #[serde(default)]
    pub description: Option<String>,
    /// How the item relates to the catalogue.
    pub classification: ProductImportClassification,
    /// The kind the item would be, or is, in the catalogue.
    pub kind: ProductKind,
    /// The catalogue product that references it, when one does.
    #[serde(default)]
    pub product_id: Option<String>,
    /// The item's prices of `kind`; a one-time price has no `interval`.
    #[serde(default)]
    pub prices: Vec<ProductImportPricePreview>,
    /// Why the item is conflicting, or which of its prices were left out.
    #[serde(default)]
    pub note: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What the import can and cannot read from a provider, so an `unchanged`
/// verdict is read for what it covers.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductImportCapabilities {
    /// The connector, e.g. `"stripe"`.
    pub connector: String,
    /// One-time products are read.
    pub one_time_products: bool,
    /// Recurring products are read.
    pub recurring_products: bool,
    /// Whether the provider lists items it no longer offers. When `false`, an
    /// item withdrawn there stops appearing and is never `unavailable`.
    pub availability: bool,
    /// Whether the provider reports a price's trial period.
    pub trial_periods: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What an import preview found, or what an apply did.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductImportCounts {
    /// Items not in the catalogue yet.
    pub new: i32,
    /// Items with prices the catalogue does not have.
    pub changed: i32,
    /// Items in the catalogue as the provider has them.
    pub unchanged: i32,
    /// Tied items the provider no longer offers.
    pub unavailable: i32,
    /// Items that cannot be imported.
    pub conflicting: i32,
    /// Products created. Filled by an apply.
    pub products_created: i32,
    /// Prices added. Filled by an apply.
    pub prices_added: i32,
    /// Items that failed. Filled by an apply.
    pub failed: i32,
    /// Catalogue products archived because the provider no longer offers
    /// them, when the apply asked for that. `None` from an older API.
    #[serde(default)]
    pub archived: Option<i32>,
    /// The provider listed as many items as the import reads and may hold
    /// more: only the items shown were classified. `None` on a run recorded
    /// before this was reported.
    #[serde(default)]
    pub listing_truncated: Option<bool>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a connected account's catalogue holds, and how each item relates to
/// the shop's catalogue.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductImportPreviewResponse {
    /// Identifies what this preview read. Send it as the apply's
    /// `confirmation`: an apply confirmed with it writes nothing if the
    /// provider's listing or the catalogue's ties moved since.
    pub confirmation: String,
    /// What the import can read from the provider.
    pub capabilities: ProductImportCapabilities,
    /// What the preview found.
    pub counts: ProductImportCounts,
    /// One entry per provider item.
    #[serde(default)]
    pub items: Vec<ProductImportItemPreview>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One item an import apply could not bring over.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductImportFailure {
    /// The provider's id for the product.
    pub connector_product_id: String,
    /// Which of the two products of a split item failed; `None` on a run
    /// recorded before splits existed.
    #[serde(default)]
    pub kind: Option<ProductKind>,
    /// The item's name.
    pub name: String,
    /// Why it failed.
    pub reason: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What one import did.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductImportRunResponse {
    /// Run ID.
    pub id: String,
    /// The connected account imported from.
    pub merchant_connector_id: String,
    /// The connector, e.g. `"stripe"`.
    pub connector: String,
    /// `applied` when every item landed, `partial` when some failed,
    /// `outdated` when the confirmation no longer matched and nothing was
    /// written.
    pub status: String,
    /// The provider or the catalogue moved since the confirmed preview;
    /// nothing was written. Preview again. `None` from an older API.
    #[serde(default)]
    pub confirmation_outdated: Option<bool>,
    /// What the run did.
    pub counts: ProductImportCounts,
    /// The items that failed, with their reasons.
    #[serde(default)]
    pub failures: Vec<ProductImportFailure>,
    /// ISO 8601 creation timestamp.
    pub created_at: String,
    /// When the run finished.
    #[serde(default)]
    pub finished_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The shop's past imports from one connected account, newest first.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductImportRunListResponse {
    /// The runs.
    #[serde(default)]
    pub data: Vec<ProductImportRunResponse>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A price's terms as the catalogue or the provider states them.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderPriceTerms {
    /// In the smallest unit of `currency`.
    pub amount: i64,
    /// Upper case.
    pub currency: String,
    /// The billing unit; `None` for a one-time price.
    #[serde(default)]
    pub interval: Option<ProductPriceInterval>,
    /// How many `interval`s one billing period lasts.
    #[serde(default)]
    pub interval_count: Option<i32>,
    /// Whether the price is active.
    pub active: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One difference between the catalogue and the provider.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderSyncDifference {
    /// Opaque. Identifies the difference and fingerprints both sides'
    /// values. Send it back in a push's `confirmed` exactly as received.
    pub key: String,
    /// The field that differs.
    pub field: ProviderSyncField,
    /// The catalogue price concerned.
    #[serde(default)]
    pub price_id: Option<String>,
    /// The provider price concerned.
    #[serde(default)]
    pub connector_price_id: Option<String>,
    /// The catalogue's value of a product field.
    #[serde(default)]
    pub catalog_value: Option<String>,
    /// The provider's value of a product field.
    #[serde(default)]
    pub provider_value: Option<String>,
    /// The catalogue's price terms.
    #[serde(default)]
    pub catalog_price: Option<ProviderPriceTerms>,
    /// The provider's price terms.
    #[serde(default)]
    pub provider_price: Option<ProviderPriceTerms>,
    /// What a push does about it; `None` when a push leaves it as it is.
    #[serde(default)]
    pub push_action: Option<ProviderPushAction>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The product's copy at one connected account.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductProviderLink {
    /// The connected account.
    pub merchant_connector_id: String,
    /// The connector, e.g. `"stripe"`.
    pub connector: String,
    /// The provider's id for the product; empty while `not_linked`.
    pub connector_product_id: String,
    /// `true` when read in the account's sandbox, `false` live.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// How the copy compares with the catalogue.
    pub status: ProviderSyncStatus,
    /// Empty unless `changed_at_provider`.
    #[serde(default)]
    pub differences: Vec<ProviderSyncDifference>,
    /// Why the status is `unknown` or `missing_at_provider`.
    #[serde(default)]
    pub reason: Option<String>,
    /// Whether this provider can be updated from the catalogue.
    pub can_push: bool,
    /// Whether the product can be created at this account. `None` from an
    /// older API.
    #[serde(default)]
    pub can_create: Option<bool>,
    /// The fields compared; a field not listed is never reported.
    #[serde(default)]
    pub compared_fields: Vec<ProviderSyncField>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// How a product compares with its copy at every account it is tied to.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductProviderSyncResponse {
    /// The product.
    pub product_id: String,
    /// The least reassuring status of the tied `links`; `not_linked` when
    /// the product is tied to no account.
    pub status: ProviderSyncStatus,
    /// One entry per account, including, as `not_linked`, the shop's
    /// billing-capable accounts the product is not tied to.
    #[serde(default)]
    pub links: Vec<ProductProviderLink>,
    /// When the providers were read.
    pub checked_at: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// [`ProductProviderSyncResponse`] for several products.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductProviderSyncBatchResponse {
    /// One entry per known product.
    #[serde(default)]
    pub data: Vec<ProductProviderSyncResponse>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One provider write a push made.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderPushStep {
    /// What was written.
    pub action: ProviderPushAction,
    /// The differences the write settled.
    #[serde(default)]
    pub keys: Vec<String>,
    /// The catalogue price concerned.
    #[serde(default)]
    pub price_id: Option<String>,
    /// The new provider price for `create_price` and `replace_price`.
    #[serde(default)]
    pub connector_price_id: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a push to a provider did.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductProviderPushResponse {
    /// `true` when nothing pushable differed; no provider write was made.
    pub nothing_to_push: bool,
    /// `true` when the push would have changed a difference not named in
    /// `confirmed`: nothing was written, and `result` holds the current
    /// differences to review and confirm again.
    pub confirmation_outdated: bool,
    /// The writes made.
    #[serde(default)]
    pub applied: Vec<ProviderPushStep>,
    /// Why the push stopped early; `applied` stays made, and pushing again
    /// continues.
    #[serde(default)]
    pub error: Option<String>,
    /// The product compared again after the push.
    pub result: ProductProviderSyncResponse,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What the catalogue can do with one connected account.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderCapabilities {
    /// Products can be read and imported.
    pub read_catalog: bool,
    /// One-time products are read and can be created.
    pub one_time_products: bool,
    /// Recurring products are read and can be created.
    pub recurring_products: bool,
    /// Differences can be pushed to the provider.
    pub push: bool,
    /// A product can be created at the provider.
    pub create: bool,
    /// What a delete can do at the provider.
    pub archive: ProviderArchiveMode,
    /// A product sold both once and on a schedule is imported as two
    /// products. Off, it is imported as recurring only.
    pub split_mixed_imports: bool,
    /// Why the catalogue cannot work with this account right now; `None`
    /// when it can.
    #[serde(default)]
    pub unavailable_reason: Option<ProviderUnavailableReason>,
    /// The environment `unavailable_reason` is about.
    #[serde(default)]
    pub unavailable_environment: Option<ProviderEnvironment>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A connected account of the shop the catalogue can work with.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderAccount {
    /// The connected account.
    pub merchant_connector_id: String,
    /// The connector, e.g. `"stripe"`.
    pub connector: String,
    /// The account's own label.
    #[serde(default)]
    pub label: Option<String>,
    /// The account's current environment: `true` for its sandbox.
    pub test_mode: bool,
    /// Whether the account is disabled.
    pub disabled: bool,
    /// The shop's billing processor, which subscriptions are created on.
    pub billing_processor: bool,
    /// The account may be the shop's billing processor.
    pub serves_subscriptions: bool,
    /// What the catalogue can do with the account.
    pub capabilities: ProviderCapabilities,
    /// When a catalogue import from this account last ran (UTC, ISO 8601).
    #[serde(default)]
    pub last_import_at: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// The shop's connected accounts the catalogue works with.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderAccountListResponse {
    /// The accounts.
    #[serde(default)]
    pub data: Vec<ProviderAccount>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A catalogue price a create would carry to the provider.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderCreatePrice {
    /// The catalogue price.
    pub price_id: String,
    /// The terms it is created with.
    pub terms: ProviderPriceTerms,
    /// Becomes the provider's default price.
    pub is_default: bool,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A catalogue price the provider cannot hold, and why.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderUnsupportedPrice {
    /// The catalogue price.
    pub price_id: String,
    /// Why the provider cannot hold it.
    pub reason: String,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a create writes at the provider.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderCreatePlan {
    /// Identifies this exact plan; a create is confirmed with it.
    pub fingerprint: String,
    /// The connector, e.g. `"stripe"`.
    pub connector: String,
    /// The connected account.
    pub merchant_connector_id: String,
    /// The environment the product is created in: `true` for the account's
    /// sandbox.
    pub test_mode: bool,
    /// The product's name.
    pub name: String,
    /// The product's description.
    #[serde(default)]
    pub description: Option<String>,
    /// The product's image.
    #[serde(default)]
    pub image_url: Option<String>,
    /// The prices to create.
    #[serde(default)]
    pub prices: Vec<ProviderCreatePrice>,
    /// Chosen prices the provider cannot hold; they are not created.
    #[serde(default)]
    pub unsupported_prices: Vec<ProviderUnsupportedPrice>,
    /// Catalogue prices not created because they are archived.
    #[serde(default)]
    pub skipped_price_ids: Vec<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// One price of a create: the provider's id, or why it was not created.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderCreatedPrice {
    /// The catalogue price.
    pub price_id: String,
    /// The provider object the price lives on.
    #[serde(default)]
    pub connector_product_id: Option<String>,
    /// The provider's id for the price.
    #[serde(default)]
    pub connector_price_id: Option<String>,
    /// Why the price was not created.
    #[serde(default)]
    pub error: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a create at a provider did, or the plan it would carry out.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductProviderCreateResponse {
    /// `true` once the product exists at the provider and is tied to the
    /// catalogue product, with every price in `prices` that has a
    /// `connector_price_id`.
    pub created: bool,
    /// `true` when `confirmed` named another plan than the current one;
    /// nothing was written, and `plan` is the current one to review.
    pub confirmation_outdated: bool,
    /// The plan.
    pub plan: ProviderCreatePlan,
    /// The provider's id for the created product.
    #[serde(default)]
    pub connector_product_id: Option<String>,
    /// One entry per price.
    #[serde(default)]
    pub prices: Vec<ProviderCreatedPrice>,
    /// Why the create stopped. What the provider already made is reused when
    /// the create is confirmed again.
    #[serde(default)]
    pub error: Option<String>,
    /// The product compared with its providers after the create.
    #[serde(default)]
    pub result: Option<ProductProviderSyncResponse>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What an archive did at one connected account.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderArchiveOutcome {
    /// The connected account.
    pub merchant_connector_id: String,
    /// The connector, e.g. `"stripe"`.
    pub connector: String,
    /// The provider object acted on.
    pub connector_product_id: String,
    /// The action asked for.
    pub action: ProviderArchiveAction,
    /// What became of it.
    pub status: ProviderArchiveStatus,
    /// Provider prices or plans deactivated.
    #[serde(default)]
    pub deactivated_price_ids: Vec<String>,
    /// Provider prices left active, such as the default price of an archived
    /// product the provider does not deactivate. An archived product takes no
    /// new sales through them.
    #[serde(default)]
    pub kept_price_ids: Vec<String>,
    /// Why the action was unsupported or failed.
    #[serde(default)]
    pub reason: Option<String>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// What a delete with provider clean-up did.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProductDeleteResponse {
    /// The product.
    pub product_id: String,
    /// Whether the product is deleted.
    pub deleted: bool,
    /// One outcome per connected account acted on.
    #[serde(default)]
    pub provider: Vec<ProviderArchiveOutcome>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// A provider clean-up still to be carried out: one that failed, or one a
/// delete recorded and never reached (`attempted_at` empty).
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderCleanup {
    /// The product.
    pub product_id: String,
    /// The product's name.
    pub product_name: String,
    /// The product is deleted; the clean-up is what is left of it.
    pub deleted: bool,
    /// The connected account.
    pub merchant_connector_id: String,
    /// The connector, e.g. `"stripe"`.
    pub connector: String,
    /// The provider object to act on; pass it to a retry.
    pub connector_product_id: String,
    /// The action to retry.
    pub action: ProviderArchiveAction,
    /// Why the last attempt failed.
    #[serde(default)]
    pub error: Option<String>,
    /// When the clean-up was last attempted.
    #[serde(default)]
    pub attempted_at: Option<String>,
    /// The environment the provider object belongs to: `true` for sandbox.
    #[serde(default)]
    pub test_mode: Option<bool>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}

/// Provider clean-ups still to be carried out.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct ProviderCleanupListResponse {
    /// The clean-ups.
    #[serde(default)]
    pub data: Vec<ProviderCleanup>,
    /// Any additional response fields not modeled above.
    #[serde(flatten)]
    pub extra: serde_json::Map<String, Value>,
}