invoist 1.0.1

Official Rust client for the Invoist API: extract invoices, read a household's bills, verify webhooks.
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
//! Request and response types, generated from the API's OpenAPI document.
//!
//! Money is always an `i64` in minor units (cents). Timestamps are RFC 3339
//! strings in UTC and dates are `YYYY-MM-DD` strings, exactly as the API sends
//! them. Fields the API adds later are ignored, and enum values it adds later
//! arrive as `Other`, so a newer API never breaks an older SDK.
//!
//! Every struct is `#[non_exhaustive]`: the API adds fields, and reading them
//! must not be a breaking change. Build values from JSON with `serde_json` when
//! a test needs one.

// @generated by `cargo run -p invoist-codegen` from testdata/openapi.yaml.
// Do not edit by hand.

use serde::{Deserialize, Serialize};

/// Why a request, or one file of a batch, was refused.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ErrorDetail {
    /// A stable machine-readable identifier. Branch on this, not the message.
    pub code: String,
    /// Human-readable explanation. Wording may change; do not parse it.
    pub message: String,
}

/// One file's outcome from POST /v1/extract/batch. A rejected file carries `error` and omits
/// the document fields; an accepted one carries the document fields and omits `error`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BatchResultItem {
    /// The file's name as sent.
    pub filename: String,
    /// The document's ID.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub document_id: Option<String>,
    /// The extraction's ID.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub extraction_id: Option<String>,
    /// The new document's status.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub status: Option<DocumentStatus>,
    /// True when this file's bytes were already extracted in this workspace.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub duplicate: Option<bool>,
    /// Present only when this file was rejected.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<ErrorDetail>,
}

crate::string_enum! {
    /// Where a document's processing stands.
    DocumentStatus {
        /// `pending`
        Pending = "pending",
        /// `processing`
        Processing = "processing",
        /// `done`
        Done = "done",
        /// `failed`
        Failed = "failed",
    }
}

crate::string_enum! {
    /// How the document arrived.
    DocumentSource {
        /// `api`
        Api = "api",
        /// `dashboard`
        Dashboard = "dashboard",
        /// `email`
        Email = "email",
        /// `storage`
        Storage = "storage",
        /// `sandbox`
        Sandbox = "sandbox",
    }
}

/// A stored document: the uploaded file and where its processing stands.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Document {
    /// Unique identifier (a UUID).
    pub id: String,
    /// How the document arrived.
    pub source: DocumentSource,
    /// The file name as it was uploaded.
    pub original_filename: String,
    /// The file's media type, e.g. `application/pdf`.
    pub content_type: String,
    /// The file's size in bytes.
    pub byte_size: i64,
    /// Where it stands.
    pub status: DocumentStatus,
    /// Sign-off state, separate from extraction progress.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approval: Option<DocumentApproval>,
    /// When it was created (RFC 3339, UTC).
    pub created_at: String,
    /// When it last changed (RFC 3339, UTC).
    pub updated_at: String,
}

/// Sign-off state. Separate from `status`, which tracks extraction: this is a person's
/// judgement, that is the machine's progress. Always "draft" unless the workspace has an
/// approval mode switched on.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DocumentApproval {
    /// Where the sign-off stands.
    pub state: DocumentApprovalState,
    /// Who submitted it for approval.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub submitted_by: Option<String>,
    /// Captured at the time, so it survives the person leaving.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub submitted_by_name: Option<String>,
    /// When it was submitted for approval (RFC 3339, UTC).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub submitted_at: Option<String>,
    /// Who approved it.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approved_by: Option<String>,
    /// The approver's name, captured at the time.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approved_by_name: Option<String>,
    /// When it was approved (RFC 3339, UTC).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approved_at: Option<String>,
}

crate::string_enum! {
    /// The values of `DocumentApproval.state`.
    DocumentApprovalState {
        /// `draft`
        Draft = "draft",
        /// `ready`
        Ready = "ready",
        /// `approved`
        Approved = "approved",
        /// `changes_requested`
        ChangesRequested = "changes_requested",
    }
}

/// A document plus a flat summary of its latest extraction.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DocumentListItem {
    /// Unique identifier (a UUID).
    pub id: String,
    /// How the document arrived.
    pub source: DocumentSource,
    /// The file name as it was uploaded.
    pub original_filename: String,
    /// The file's media type, e.g. `application/pdf`.
    pub content_type: String,
    /// The file's size in bytes.
    pub byte_size: i64,
    /// Where it stands.
    pub status: DocumentStatus,
    /// The seller as printed on the document.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub vendor_name: Option<String>,
    /// The invoice number as printed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub invoice_number: Option<String>,
    /// The payment or bank reference, distinct from the invoice number.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reference_number: Option<String>,
    /// The total, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub total_cents: Option<i64>,
    /// The workspace's reporting currency, when one is configured. Null when conversion is off,
    /// or when this invoice's currency had no published rate for its date. The invoice's own
    /// currency and total_cents remain authoritative.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub base_currency: Option<String>,
    /// total_cents converted into base_currency, for reporting only.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub base_total_cents: Option<i64>,
    /// Reporting-currency units per one unit of the invoice currency, as a decimal string so
    /// the exact stored value round-trips.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fx_rate: Option<String>,
    /// The date of the published rates used, which is the invoice date or the most recent
    /// publication before it.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fx_rate_date: Option<String>,
    /// Who published the rate, e.g. "ecb".
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fx_source: Option<String>,
    /// ISO 4217 currency code, e.g. `EUR`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub currency: Option<String>,
    /// The spend category's ID, when it has one.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub category_id: Option<String>,
    /// The spend category's name, when it has one.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub category_name: Option<String>,
    /// Count of unresolved review items.
    pub pending_review: i64,
    /// True when pending_review is above zero.
    pub flagged: bool,
    /// When it was created (RFC 3339, UTC).
    pub created_at: String,
    /// When it last changed (RFC 3339, UTC).
    pub updated_at: String,
}

crate::string_enum! {
    /// Where reading a document stands: `pending` until it finishes, then `done` or `failed`.
    ExtractionStatus {
        /// `pending`
        Pending = "pending",
        /// `done`
        Done = "done",
        /// `failed`
        Failed = "failed",
    }
}

/// The data read from a document: header fields, line items, confidence scores, and
/// observations worth a second look.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Extraction {
    /// Unique identifier (a UUID).
    pub id: String,
    /// The document's ID.
    pub document_id: String,
    /// The engine that read the document, e.g. `invoist-extraction-v1`.
    pub engine: String,
    /// Where it stands.
    pub status: ExtractionStatus,
    /// What the document is. Null when the reader could not tell, and on documents read before
    /// this field existed; treat null as an ordinary invoice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub document_kind: Option<BillKind>,
    /// The invoice number as printed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub invoice_number: Option<String>,
    /// Absent when not printed on the document.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub invoice_date: Option<String>,
    /// Absent when not printed on the document.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub due_date: Option<String>,
    /// The purchase order number, when printed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub po_number: Option<String>,
    /// The payment or bank reference, distinct from the invoice number.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reference_number: Option<String>,
    /// The seller as printed on the document.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub vendor_name: Option<String>,
    /// The seller's address as printed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub vendor_address: Option<String>,
    /// The buyer as printed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub customer_name: Option<String>,
    /// ISO 4217 code, e.g. EUR.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub currency: Option<String>,
    /// The total before tax, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub subtotal_cents: Option<i64>,
    /// The tax, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub tax_cents: Option<i64>,
    /// The total, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub total_cents: Option<i64>,
    /// The workspace's reporting currency, when one is configured. Null when conversion is off,
    /// or when this invoice's currency had no published rate for its date.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub base_currency: Option<String>,
    /// total_cents converted into base_currency, for reporting only.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub base_total_cents: Option<i64>,
    /// Reporting-currency units per one unit of the invoice currency, as a decimal string.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fx_rate: Option<String>,
    /// The date of the published rates used.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fx_rate_date: Option<String>,
    /// Who published the rate, e.g. "ecb".
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fx_source: Option<String>,
    /// Per-field confidence between 0 and 1, keyed by field name.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub confidence: Option<std::collections::BTreeMap<String, f64>>,
    /// The document's line items, in printed order.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub line_items: Option<Vec<LineItem>>,
    /// Optional commercial extras (payment terms, tax IDs, IBAN, shipping). On a reminder,
    /// collection letter or credit note it also carries original_invoice_number,
    /// original_invoice_date, original_creditor, original_amount_cents, fees_cents and
    /// interest_cents: the earlier invoice it is about and what was added.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub details: Option<serde_json::Map<String, serde_json::Value>>,
    /// Heuristic observations worth a second look. Never a determination that a document is
    /// fraudulent.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fraud_indicators: Option<Vec<FraudIndicator>>,
    /// Facts read from the file's own EXIF or PDF metadata, never inferred.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub file_metadata: Option<serde_json::Map<String, serde_json::Value>>,
    /// Workspace-declared custom fields, filled during extraction.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub custom: Vec<CustomValue>,
    /// Coordinate-pinned findings on the first page image.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub discoveries: Vec<Discovery>,
    /// How legible the document was.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub quality: Option<Quality>,
    /// The spend category's ID, when it has one.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub category_id: Option<String>,
    /// Who chose the category.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub category_source: Option<ExtractionCategorySource>,
    /// True when this skipped the review queue because the vendor had a clean track record.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub auto_approved: Option<bool>,
    /// Why reading failed, when `status` is `failed`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error_message: Option<String>,
    /// When it was created (RFC 3339, UTC).
    pub created_at: String,
    /// When it last changed (RFC 3339, UTC).
    pub updated_at: String,
    /// When a person last corrected these fields by hand. Absent if the extraction has never
    /// been edited, so its presence is how you tell a human-reviewed record from a purely
    /// automatic one.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub edited_at: Option<String>,
}

crate::string_enum! {
    /// The values of `Extraction.category_source`.
    ExtractionCategorySource {
        /// `model`
        Model = "model",
        /// `user`
        User = "user",
        /// `memory`
        Memory = "memory",
    }
}

/// Progress of the background run that produces an extraction. Reading a document is queued
/// work, so this reports how that work is going: whether it is waiting, running, finished, or
/// has given up.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ExtractionJob {
    /// `queued` is waiting for a worker, which includes waiting out the backoff between
    /// attempts. `failed` means every attempt was used or the failure was one that retrying
    /// cannot fix.
    pub status: ExtractionJobStatus,
    /// Attempts made so far, including the one currently running.
    pub attempt_count: i64,
    /// Attempts allowed before the run is abandoned. Deliberately small, since every attempt is
    /// a real extraction.
    pub max_attempts: i64,
    /// True when the run has stopped and can be started again. Retrying is a fresh run and is
    /// billed as one.
    pub retryable: bool,
    /// When the next attempt is due. Present only while a retry is genuinely still coming, so
    /// its absence on a queued job means the job has not started yet rather than that it is
    /// stalled.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub next_attempt_at: Option<String>,
}

crate::string_enum! {
    /// The values of `ExtractionJob.status`.
    ExtractionJobStatus {
        /// `queued`
        Queued = "queued",
        /// `running`
        Running = "running",
        /// `succeeded`
        Succeeded = "succeeded",
        /// `failed`
        Failed = "failed",
    }
}

/// One line of a document.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct LineItem {
    /// The line's text.
    pub description: String,
    /// How many units.
    pub quantity: f64,
    /// The unit, e.g. `kWh` or `pcs`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub unit: Option<String>,
    /// The article number, when printed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sku: Option<String>,
    /// Unit price in whole cents. Null when the price is not an exact number of cents, which
    /// happens on utility and fuel invoices priced per unit below one cent. Read
    /// unit_price_micros for those.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub unit_price_cents: Option<i64>,
    /// Unit price in millionths of one currency unit, exact for sub-cent prices. 8.72 cents per
    /// kWh is 87200. Set whenever a unit price is printed, including when unit_price_cents is
    /// also set.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub unit_price_micros: Option<i64>,
    /// The line's total, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub line_total_cents: Option<i64>,
    /// The line's tax, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub tax_cents: Option<i64>,
    /// The line's discount, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub discount_cents: Option<i64>,
}

/// A heuristic observation worth a second look. Never a determination that a document is
/// fraudulent.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct FraudIndicator {
    /// Model-reported signals are one of `math_mismatch`, `font_inconsistency`,
    /// `implausible_dates`, `round_total`, `vendor_details_off`, `possible_edit`.
    /// Engine-reported signals add `vendor_bank_change` and `vendor_amount_anomaly`.
    pub signal: String,
    /// How much it matters.
    pub severity: FraudIndicatorSeverity,
    /// What was observed, in words.
    pub description: String,
    /// `model` when read off the page; `engine` when derived from workspace history.
    pub source: FraudIndicatorSource,
    /// 1-based page number when the finding has a location.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// Where on the page, when the finding has a location.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub r#box: Option<RegionBox>,
}

crate::string_enum! {
    /// The values of `FraudIndicator.severity`.
    FraudIndicatorSeverity {
        /// `low`
        Low = "low",
        /// `medium`
        Medium = "medium",
        /// `high`
        High = "high",
    }
}

crate::string_enum! {
    /// The values of `FraudIndicator.source`.
    FraudIndicatorSource {
        /// `model`
        Model = "model",
        /// `engine`
        Engine = "engine",
    }
}

/// A rectangle on the page image, normalized 0 to 1, origin top-left.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct RegionBox {
    /// Left edge, 0 to 1.
    pub x: f64,
    /// Top edge, 0 to 1.
    pub y: f64,
    /// Width, 0 to 1.
    pub w: f64,
    /// Height, 0 to 1.
    pub h: f64,
}

/// A URL subscribed to signed events.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WebhookEndpoint {
    /// Unique identifier (a UUID).
    pub id: String,
    /// Where events are delivered.
    pub url: String,
    /// A note to tell endpoints apart.
    pub description: String,
    /// Subscribed event types; \["\*"\] means everything.
    pub events: Vec<String>,
    /// Whether deliveries are being made.
    pub enabled: bool,
    /// Failed deliveries in a row.
    pub consecutive_failures: i64,
    /// When the last delivery was attempted (RFC 3339, UTC).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub last_delivery_at: Option<String>,
    /// The HTTP status of the last delivery.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub last_status: Option<i64>,
    /// Set when repeated failures paused this endpoint automatically.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub auto_disabled_at: Option<String>,
    /// When it was created (RFC 3339, UTC).
    pub created_at: String,
}

/// A newly registered webhook endpoint with its signing secret, which is returned only this
/// once.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WebhookEndpointWithSecret {
    /// Unique identifier (a UUID).
    pub id: String,
    /// Where events are delivered.
    pub url: String,
    /// A note to tell endpoints apart.
    pub description: String,
    /// Subscribed event types; \["\*"\] means everything.
    pub events: Vec<String>,
    /// Whether deliveries are being made.
    pub enabled: bool,
    /// Failed deliveries in a row.
    pub consecutive_failures: i64,
    /// When the last delivery was attempted (RFC 3339, UTC).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub last_delivery_at: Option<String>,
    /// The HTTP status of the last delivery.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub last_status: Option<i64>,
    /// Set when repeated failures paused this endpoint automatically.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub auto_disabled_at: Option<String>,
    /// When it was created (RFC 3339, UTC).
    pub created_at: String,
    /// HMAC key for X-Invoist-Signature. Returned only here and on rotation, never readable
    /// again.
    pub secret: String,
}

/// A finding pinned to a point on a page image.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Discovery {
    /// 1-based page this pin belongs to. Absent or 0 means page 1, which is how discoveries
    /// extracted before multi-page support are stored.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// Normalized 0 to 1 across that page's image.
    pub x: f64,
    /// Normalized 0 to 1 down that page's image.
    pub y: f64,
    /// What was found there.
    pub label: String,
}

/// A workspace-declared custom field and the value read for it.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CustomValue {
    /// The custom field's key.
    pub key: String,
    /// The custom field's label.
    pub label: String,
    /// The value read, when one was found.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub value: Option<String>,
    /// Confidence between 0 and 1.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub confidence: Option<f64>,
}

/// How legible a document was.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Quality {
    /// 0 to 1, where 1 is crisp and fully legible.
    pub readability: f64,
    /// What made it harder to read.
    pub issues: Vec<QualityIssue>,
}

crate::string_enum! {
    /// The values of `Quality.issues`.
    QualityIssue {
        /// `blurry`
        Blurry = "blurry",
        /// `cropped`
        Cropped = "cropped",
        /// `low_contrast`
        LowContrast = "low_contrast",
        /// `rotated`
        Rotated = "rotated",
        /// `handwritten`
        Handwritten = "handwritten",
        /// `partial`
        Partial = "partial",
    }
}

crate::string_enum! {
    /// Where a review item stands.
    ReviewStatus {
        /// `pending`
        Pending = "pending",
        /// `resolved`
        Resolved = "resolved",
        /// `dismissed`
        Dismissed = "dismissed",
    }
}

crate::string_enum! {
    /// Why the item was flagged.
    ReviewReason {
        /// `low_confidence`
        LowConfidence = "low_confidence",
        /// `total_mismatch`
        TotalMismatch = "total_mismatch",
        /// `poor_quality`
        PoorQuality = "poor_quality",
        /// `duplicate`
        Duplicate = "duplicate",
        /// `unusual_vendor`
        UnusualVendor = "unusual_vendor",
        /// `bank_details_changed`
        BankDetailsChanged = "bank_details_changed",
        /// `amount_anomaly`
        AmountAnomaly = "amount_anomaly",
        /// `amount_over_limit`
        AmountOverLimit = "amount_over_limit",
        /// `missing_po_number`
        MissingPoNumber = "missing_po_number",
    }
}

/// Something the engine flagged for a person to check.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ReviewQueueItem {
    /// Unique identifier (a UUID).
    pub id: String,
    /// The document's ID.
    pub document_id: String,
    /// The extraction's ID.
    pub extraction_id: String,
    /// Why it was flagged.
    pub reason: ReviewReason,
    /// Where it stands.
    pub status: ReviewStatus,
    /// When it was created (RFC 3339, UTC).
    pub created_at: String,
    /// When it was resolved (RFC 3339, UTC); absent while open.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub resolved_at: Option<String>,
}

/// A review item plus a summary of the document it belongs to.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ReviewQueueListItem {
    /// Unique identifier (a UUID).
    pub id: String,
    /// The document's ID.
    pub document_id: String,
    /// The extraction's ID.
    pub extraction_id: String,
    /// Why it was flagged.
    pub reason: ReviewReason,
    /// Where it stands.
    pub status: ReviewStatus,
    /// When it was created (RFC 3339, UTC).
    pub created_at: String,
    /// When it was resolved (RFC 3339, UTC); absent while open.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub resolved_at: Option<String>,
    /// The file name as it was uploaded.
    pub original_filename: String,
    /// The file's media type, e.g. `application/pdf`.
    pub content_type: String,
    /// The document's status.
    pub document_status: DocumentStatus,
    /// The seller as printed on the document.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub vendor_name: Option<String>,
    /// The invoice number as printed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub invoice_number: Option<String>,
    /// The payment or bank reference, distinct from the invoice number.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reference_number: Option<String>,
    /// The total, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub total_cents: Option<i64>,
    /// ISO 4217 currency code, e.g. `EUR`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub currency: Option<String>,
}

/// A spend category documents are sorted into.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Category {
    /// Unique identifier (a UUID).
    pub id: String,
    /// The category's name.
    pub name: String,
    /// Part of the set seeded with the workspace.
    pub is_default: bool,
    /// When it was created (RFC 3339, UTC).
    pub created_at: String,
}

/// Usage for the current billing period.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Usage {
    /// When the billing period began (RFC 3339, UTC).
    pub period_start: String,
    /// API calls made this period.
    pub total_calls: i64,
    /// Documents extracted this period.
    pub total_documents: i64,
    /// The period's cost so far, in minor currency units (cents).
    pub total_cost_cents: i64,
    /// The same, day by day.
    pub by_day: Vec<UsageByDay>,
}

/// An entry of `Usage.by_day`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct UsageByDay {
    /// The day (`YYYY-MM-DD`).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub day: Option<String>,
    /// API calls made that day.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub calls: Option<i64>,
    /// Documents extracted that day.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub documents: Option<i64>,
}

/// Workspace statistics: document counts, pending review, and plan allowance.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct StatsOverview {
    /// Documents added this month.
    pub documents_this_month: i64,
    /// Documents in the workspace.
    pub documents_total: i64,
    /// Review items waiting for a person.
    pub pending_review_count: i64,
    /// When the billing period began (RFC 3339, UTC).
    pub period_start: String,
    /// The workspace's plan.
    pub plan: StatsOverviewPlan,
    /// Monthly allowance for the plan. Absent for plans without a fixed allowance.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub documents_included: Option<i64>,
}

crate::string_enum! {
    /// The values of `StatsOverview.plan`.
    StatsOverviewPlan {
        /// `starter`
        Starter = "starter",
        /// `growth`
        Growth = "growth",
        /// `scale`
        Scale = "scale",
    }
}

/// The household's own record on a bill.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillRecord {
    /// When it was marked paid.
    #[serde(default)]
    pub paid_at: Option<String>,
    /// Who marked it paid.
    #[serde(default)]
    pub paid_by: Option<String>,
    /// Who is meant to pay it.
    #[serde(default)]
    pub assigned_to: Option<String>,
}

crate::string_enum! {
    /// What a document is. Null is an ordinary invoice.
    BillKind {
        /// `invoice`
        Invoice = "invoice",
        /// `reminder`
        Reminder = "reminder",
        /// `debt_collection`
        DebtCollection = "debt_collection",
        /// `credit_note`
        CreditNote = "credit_note",
        /// `receipt`
        Receipt = "receipt",
        /// `payment_confirmation`
        PaymentConfirmation = "payment_confirmation",
    }
}

/// The bill a letter or receipt is linked to, and how.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillRelated {
    /// The document's ID.
    #[serde(default)]
    pub document_id: Option<String>,
    /// `matched` or `confirmed` when linked, `suggested` when Invoist only thinks so, empty
    /// when unlinked.
    pub link: String,
}

/// The newest reminder or collection letter about a bill, which says what is owed now.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillLetter {
    /// The document's ID.
    pub document_id: String,
    /// A reminder or a collection letter.
    pub kind: BillLetterKind,
    /// What is owed now, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub total_cents: Option<i64>,
    /// ISO 4217 currency code, e.g. `EUR`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub currency: Option<String>,
    /// When the letter says to pay (`YYYY-MM-DD`).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub due_date: Option<String>,
    /// Fees and interest added on top of the original.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub added_cents: Option<i64>,
    /// How many letters came for this bill.
    pub count: i64,
}

crate::string_enum! {
    /// The values of `BillLetter.kind`.
    BillLetterKind {
        /// `reminder`
        Reminder = "reminder",
        /// `debt_collection`
        DebtCollection = "debt_collection",
    }
}

/// One bill in a household's list.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Bill {
    /// Unique identifier (a UUID).
    pub id: String,
    /// How the document arrived.
    pub source: DocumentSource,
    /// The file name as it was uploaded.
    pub original_filename: String,
    /// The file's media type, e.g. `application/pdf`.
    pub content_type: String,
    /// The file's size in bytes.
    pub byte_size: i64,
    /// Where it stands.
    pub status: DocumentStatus,
    /// The seller as printed on the document.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub vendor_name: Option<String>,
    /// The invoice number as printed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub invoice_number: Option<String>,
    /// The payment or bank reference, distinct from the invoice number.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reference_number: Option<String>,
    /// The total, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub total_cents: Option<i64>,
    /// The workspace's reporting currency, when one is configured. Null when conversion is off,
    /// or when this invoice's currency had no published rate for its date. The invoice's own
    /// currency and total_cents remain authoritative.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub base_currency: Option<String>,
    /// total_cents converted into base_currency, for reporting only.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub base_total_cents: Option<i64>,
    /// Reporting-currency units per one unit of the invoice currency, as a decimal string so
    /// the exact stored value round-trips.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fx_rate: Option<String>,
    /// The date of the published rates used, which is the invoice date or the most recent
    /// publication before it.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fx_rate_date: Option<String>,
    /// Who published the rate, e.g. "ecb".
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fx_source: Option<String>,
    /// ISO 4217 currency code, e.g. `EUR`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub currency: Option<String>,
    /// The spend category's ID, when it has one.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub category_id: Option<String>,
    /// The spend category's name, when it has one.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub category_name: Option<String>,
    /// Count of unresolved review items.
    pub pending_review: i64,
    /// True when pending_review is above zero.
    pub flagged: bool,
    /// When it was created (RFC 3339, UTC).
    pub created_at: String,
    /// When it last changed (RFC 3339, UTC).
    pub updated_at: String,
    /// When payment is due (`YYYY-MM-DD`).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub due_date: Option<String>,
    /// The household's own record: paid, by whom, who pays.
    pub bill: BillRecord,
    /// What the document is; `None` is an ordinary invoice.
    #[serde(default)]
    pub kind: Option<BillKind>,
    /// The bill this one is linked to, and how.
    pub related: BillRelated,
    /// The newest reminder or collection letter about this bill.
    #[serde(default)]
    pub letter: Option<BillLetter>,
    /// A receipt or payment confirmation found for this bill.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub proof_document_id: Option<String>,
    /// The domain whose logo stands for the sender, when Invoist shows one: never on a bill
    /// with an open warning, never for a domain that imitates another the household knows.
    #[serde(default)]
    pub logo: Option<String>,
}

/// One document of a bill's chain (the bill and its letters).
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillChainMember {
    /// The document's ID.
    pub document_id: String,
    /// What the document is; `None` is an ordinary invoice.
    #[serde(default)]
    pub kind: Option<BillKind>,
    /// How it is linked to the bill.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub link: Option<String>,
    /// The document's extraction status.
    pub status: DocumentStatus,
    /// The file name as it was uploaded.
    pub original_filename: String,
    /// The seller as printed on the document.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub vendor_name: Option<String>,
    /// The invoice number as printed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub invoice_number: Option<String>,
    /// The payment or bank reference, distinct from the invoice number.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reference_number: Option<String>,
    /// ISO 4217 currency code, e.g. `EUR`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub currency: Option<String>,
    /// The total, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub total_cents: Option<i64>,
    /// The document's own date (`YYYY-MM-DD`).
    pub date: String,
    /// When payment is due (`YYYY-MM-DD`).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub due_date: Option<String>,
    /// When it was marked paid (RFC 3339, UTC).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub paid_at: Option<String>,
    /// Fees added, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fees_cents: Option<i64>,
    /// Interest added, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub interest_cents: Option<i64>,
    /// The original invoice's amount, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub original_amount_cents: Option<i64>,
    /// Who the debt was first owed to.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub original_creditor: Option<String>,
    /// The IBAN to pay to.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub vendor_iban: Option<String>,
    /// The bank's BIC.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub vendor_bic: Option<String>,
    /// The account to pay to, when not an IBAN.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub payment_account: Option<String>,
    /// Its open warnings.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub warnings: Vec<BillChainMemberWarning>,
}

/// An entry of `BillChainMember.warnings`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillChainMemberWarning {
    /// The review item's ID.
    pub id: String,
    /// Why it was flagged.
    pub reason: ReviewReason,
}

/// One bill with everything read from it.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillDetail {
    /// The stored document.
    pub document: Document,
    /// The data read from the document, once an extraction exists.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub extraction: Option<Extraction>,
    /// How the background run producing the extraction is going.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub extraction_job: Option<ExtractionJob>,
    /// The bill's warnings; open ones have status `pending`.
    pub review_queue: Vec<ReviewQueueItem>,
    /// Whether this bill's month is closed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub period_locked: Option<bool>,
    /// The household's own record: paid, by whom, who pays.
    pub bill: BillRecord,
    /// The bill this document is linked to, and how.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub related: Option<BillRelated>,
    /// The bill and its letters, when it has any.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub chain: Option<BillDetailChain>,
    /// A bill Invoist thinks this letter or receipt is about.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub suggested_bill: Option<BillChainMember>,
    /// Letters Invoist thinks are about this bill.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub suggested_letters: Vec<BillChainMember>,
    /// The domain whose logo stands for the sender, when Invoist shows one.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub logo: Option<String>,
}

/// The bill and its letters, when it has any.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillDetailChain {
    /// The original bill's document ID.
    pub root_id: String,
    /// The bill and its letters, oldest first.
    pub members: Vec<BillChainMember>,
}

/// Unpaid bills that fall due soon, in one currency.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillsDue {
    /// ISO 4217 currency code, e.g. `EUR`.
    pub currency: String,
    /// How many bills.
    pub count: i64,
    /// Their total, in minor currency units (cents).
    pub total_cents: i64,
}

/// What a household has to pay: unpaid and overdue counts, and what falls due soon, per
/// currency.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillsSummary {
    /// Bills not marked paid.
    pub unpaid: i64,
    /// Unpaid bills past their due date.
    pub overdue: i64,
    /// Per currency, the unpaid bills due by today plus `days`, overdue ones included.
    pub due_soon: Vec<BillsDue>,
    /// How far ahead "due soon" reaches, in days.
    pub days: i64,
    /// The date the summary was made for (`YYYY-MM-DD`).
    pub today: String,
}

/// A household's month at a glance: totals, the twelve-month trend, and its senders.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillsStats {
    /// `YYYY-MM`
    pub month: String,
    /// The month's totals, per currency.
    pub totals: Vec<BillsStatsTotal>,
    /// Up to twelve months ending with `month`, per currency; months with no bills are absent.
    pub trend: Vec<BillsStatsTrend>,
    /// The five biggest senders this month.
    pub top_senders: Vec<BillsStatsTopSender>,
    /// Everyone who has sent the household bills, most bills first.
    pub senders: Vec<BillsStatsSender>,
}

/// An entry of `BillsStats.totals`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillsStatsTotal {
    /// ISO 4217 currency code, e.g. `EUR`.
    pub currency: String,
    /// Bills this month.
    pub count: i64,
    /// Of those, marked paid.
    pub paid_count: i64,
    /// Billed this month, in minor currency units (cents).
    pub total_cents: i64,
    /// Paid of that, in minor currency units (cents).
    pub paid_cents: i64,
}

/// An entry of `BillsStats.trend`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillsStatsTrend {
    /// The month, `YYYY-MM`.
    pub month: String,
    /// ISO 4217 currency code, e.g. `EUR`.
    pub currency: String,
    /// Bills that month.
    pub count: i64,
    /// Billed that month, in minor currency units (cents).
    pub total_cents: i64,
}

/// An entry of `BillsStats.top_senders`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillsStatsTopSender {
    /// The sender.
    pub name: String,
    /// ISO 4217 currency code, e.g. `EUR`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub currency: Option<String>,
    /// Their bills this month.
    pub count: i64,
    /// Their total this month, in minor currency units (cents).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub total_cents: Option<i64>,
    /// The domain whose logo stands for the sender, when Invoist shows one.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub logo: Option<String>,
}

/// An entry of `BillsStats.senders`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BillsStatsSender {
    /// The sender.
    pub name: String,
    /// How many bills they sent.
    pub count: i64,
}

/// An attachment of a held email.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct HeldEmailFile {
    /// Unique identifier (a UUID).
    pub id: String,
    /// The file name.
    pub filename: String,
    /// The file's media type, e.g. `application/pdf`.
    pub content_type: String,
    /// The file's size in bytes.
    pub size_bytes: i64,
}

/// An email forwarded to the household that waits for approval.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct HeldEmail {
    /// Unique identifier (a UUID).
    pub id: String,
    /// The From address.
    pub from_email: String,
    /// The subject line.
    pub subject: String,
    /// Where it stands.
    pub status: String,
    /// A note on why it waits, in words.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub reason: Option<String>,
    /// How many attachments it carried.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub attachments: Option<i64>,
    /// How many documents it would add.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub documents: Option<i64>,
    /// When it was created (RFC 3339, UTC).
    pub created_at: String,
    /// Why it waits. The sender reasons wait for a person; the plan reasons clear by
    /// themselves.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub hold_reason: Option<HeldEmailHoldReason>,
    /// When it is deleted if nobody acts.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub held_until: Option<String>,
    /// When it was resolved (RFC 3339, UTC); absent while open.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub resolved_at: Option<String>,
    /// Whether it was bounced back to the sender.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub bounced: Option<bool>,
    /// The household member whose forwarding rule passed it on.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub forwarded_by: Option<String>,
    /// Who wrote it first, when forwarded by hand.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub original_from: Option<String>,
    /// A known domain this sender's imitates.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub lookalike_of: Option<String>,
    /// What the mail server found about the From address.
    pub sender: HeldEmailSender,
    /// Its attachments.
    pub files: Vec<HeldEmailFile>,
    /// The domain whose logo stands for the sender, when Invoist shows one.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub logo: Option<String>,
}

crate::string_enum! {
    /// The values of `HeldEmail.hold_reason`.
    HeldEmailHoldReason {
        /// `new_sender`
        NewSender = "new_sender",
        /// `unverified_sender`
        UnverifiedSender = "unverified_sender",
        /// `no_plan`
        NoPlan = "no_plan",
        /// `quota_used`
        QuotaUsed = "quota_used",
    }
}

crate::string_enum! {
    /// The values of `HeldEmail.sender`.
    HeldEmailSender {
        /// `verified`
        Verified = "verified",
        /// `failed`
        Failed = "failed",
        /// `unknown`
        Unknown = "unknown",
    }
}

/// What `POST /v1/extract` answers: the document, its extraction, and whether these exact bytes
/// were already extracted in this workspace (`duplicate`).
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ExtractResult {
    /// The stored document.
    pub document: Document,
    /// The data read from the document, once an extraction exists.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub extraction: Option<Extraction>,
    /// True when these exact bytes were already extracted in this workspace: the existing
    /// document is returned, and nothing new was created or billed.
    pub duplicate: bool,
}

/// What `POST /v1/extract/batch` answers: one outcome per file, in the order the files were
/// sent.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BatchResult {
    /// Each file's outcome, in the order the files were sent.
    pub results: Vec<BatchResultItem>,
    /// How many files were accepted and queued.
    pub accepted: i64,
    /// How many files failed validation or could not be stored.
    pub rejected: i64,
}

/// A document with its extraction, the progress of the run producing it, and its review items.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DocumentDetail {
    /// The stored document.
    pub document: Document,
    /// The data read from the document, once an extraction exists.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub extraction: Option<Extraction>,
    /// How the background run producing the extraction is going.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub extraction_job: Option<ExtractionJob>,
    /// The document's review items.
    pub review_queue: Vec<ReviewQueueItem>,
    /// Whether this document's month is closed. A locked document can be read and exported but
    /// not edited, categorized, deleted, or re-run until the month is reopened.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub period_locked: Option<bool>,
}

/// Every registered webhook endpoint, plus the event types the API knows.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WebhookEndpointList {
    /// The registered endpoints.
    pub endpoints: Vec<WebhookEndpoint>,
    /// Every event type the API can send.
    pub known_events: Vec<String>,
}