hdm-am 0.4.0

Client for the Armenian fiscal cash register (HDM) protocol per the State Revenue Committee spec
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
use crate::wire::OperationCode;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize, Serializer};

use super::{EmptyResponse, Operation};

// `#[serde(with = "dec")]` sends/receives a `Decimal` as a JSON number (not a string), matching the
// HDM wire format; `dec_opt` is the same for `Option<Decimal>`. Aliased short for per-field use.
use rust_decimal::serde::float as dec;
use rust_decimal::serde::float_option as dec_opt;

/// Receipt print mode (spec §4.5.4).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum PrintMode {
    /// `1` — Simple lump-sum receipt. The `items` array is not used; only `dep` matters.
    Simple = 1,
    /// `2` — Itemised receipt with one or more goods.
    Products = 2,
    /// `3` — Prepayment receipt; the `items` array must be empty.
    Prepayment = 3,
}

impl Serialize for PrintMode {
    fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
        ser.serialize_u8(*self as u8)
    }
}

impl<'de> Deserialize<'de> for PrintMode {
    fn deserialize<D: serde::Deserializer<'de>>(de: D) -> Result<Self, D::Error> {
        let code = u8::deserialize(de)?;
        Ok(match code {
            1 => Self::Simple,
            2 => Self::Products,
            3 => Self::Prepayment,
            other => {
                return Err(serde::de::Error::custom(format!(
                    "unknown print mode code {other} (expected 1, 2, or 3)"
                )));
            }
        })
    }
}

/// Discount semantics per spec §4.5.4. The integer values are the wire encoding.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiscountKind {
    /// `1` — Percentage discount. `total_price * (discount/100)`.
    Percent,
    /// `2` — Price reduction per unit. `(price - discount) * quantity`.
    UnitPriceReduction,
    /// `4` — Total reduction over the line. `(price * quantity) - discount`.
    LineTotalReduction,
    /// `8` — Additional percentage discount on monetary-priced items.
    AdditionalPercent,
    /// `16` — Additional monetary discount.
    AdditionalMonetary,
}

impl DiscountKind {
    /// Numeric wire value.
    #[must_use]
    pub const fn code(self) -> u32 {
        match self {
            Self::Percent => 1,
            Self::UnitPriceReduction => 2,
            Self::LineTotalReduction => 4,
            Self::AdditionalPercent => 8,
            Self::AdditionalMonetary => 16,
        }
    }
}

impl Serialize for DiscountKind {
    fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
        ser.serialize_u32(self.code())
    }
}

impl<'de> Deserialize<'de> for DiscountKind {
    fn deserialize<D: serde::Deserializer<'de>>(de: D) -> Result<Self, D::Error> {
        let code = u32::deserialize(de)?;
        Ok(match code {
            1 => Self::Percent,
            2 => Self::UnitPriceReduction,
            4 => Self::LineTotalReduction,
            8 => Self::AdditionalPercent,
            16 => Self::AdditionalMonetary,
            other => {
                return Err(serde::de::Error::custom(format!(
                    "unknown discount kind code {other} (expected 1, 2, 4, 8, or 16)"
                )));
            }
        })
    }
}

/// Op 4 request: print a fiscal receipt. Encrypted with the session key.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PrintReceiptRequest {
    /// Mode (simple / products / prepayment).
    #[cfg_attr(feature = "schema", schemars(with = "u8"))]
    pub mode: PrintMode,
    /// Cash portion of the payment.
    #[serde(rename = "paidAmount", with = "dec")]
    #[cfg_attr(feature = "schema", schemars(with = "f64"))]
    pub paid_amount: Decimal,
    /// Card (cashless) portion of the payment.
    #[serde(rename = "paidAmountCard", with = "dec")]
    #[cfg_attr(feature = "schema", schemars(with = "f64"))]
    pub paid_amount_card: Decimal,
    /// Partial-payment portion.
    #[serde(rename = "partialAmount", with = "dec")]
    #[cfg_attr(feature = "schema", schemars(with = "f64"))]
    pub partial_amount: Decimal,
    /// Prepayment-used portion.
    #[serde(rename = "prePaymentAmount", with = "dec")]
    #[cfg_attr(feature = "schema", schemars(with = "f64"))]
    pub pre_payment_amount: Decimal,
    /// Department for simple/prepayment receipts (when `items` is empty).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dep: Option<u32>,
    /// Partner TIN (8 digits) for B2B receipts. Sent as `null` if absent — the spec requires
    /// this field to appear even when null.
    #[serde(rename = "partnerTin")]
    pub partner_tin: Option<String>,
    /// If `true`, supply `rrn` + `terminal_id` from an external POS terminal. If `false`, the
    /// HDM uses its own configured payment system (set `payment_system`).
    #[serde(rename = "useExtPOS")]
    pub use_ext_pos: bool,
    /// Payment system code from spec §4.8 (1 = card, 10-18 = various Armenian wallets). Used
    /// only when `use_ext_pos = false` and the HDM has multiple payment systems configured.
    #[serde(rename = "PaymentSystem", skip_serializing_if = "Option::is_none")]
    pub payment_system: Option<u32>,
    /// Acquirer transaction RRN (12 chars). Used when `use_ext_pos = true`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rrn: Option<String>,
    /// Payment terminal unique ID (8 chars). Used when `use_ext_pos = true`.
    #[serde(rename = "terminalId", skip_serializing_if = "Option::is_none")]
    pub terminal_id: Option<String>,
    /// eMark traceability codes for marked goods (29-110 chars each, ASCII printable, escaping
    /// rules in spec §4.5.4). Used only in product-mode receipts.
    #[serde(rename = "eMarks", default)]
    pub e_marks: Vec<String>,
    /// Items (required when `mode = Products`). Use an empty `Vec` for simple/prepayment modes.
    #[serde(default)]
    pub items: Vec<ReceiptItem>,
}

impl Operation for PrintReceiptRequest {
    const CODE: OperationCode = OperationCode::PrintReceipt;
    type Response = ReceiptResponse;
}

/// A single item in a printed receipt.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct ReceiptItem {
    /// Department this item belongs to.
    pub dep: u32,
    /// Quantity, max 3 decimal places.
    #[serde(with = "dec")]
    #[cfg_attr(feature = "schema", schemars(with = "f64"))]
    pub qty: Decimal,
    /// Unit price, max 2 decimal places.
    #[serde(with = "dec")]
    #[cfg_attr(feature = "schema", schemars(with = "f64"))]
    pub price: Decimal,
    /// Vendor SKU (≤50 chars, must be non-empty).
    #[serde(rename = "productCode")]
    pub product_code: String,
    /// Display name (≤50 chars, must be non-empty).
    #[serde(rename = "productName")]
    pub product_name: String,
    /// ATG/ADG tax classification code. Lookup at `taxservice.am`. Mandatory unless waived by
    /// item-level discount logic per spec §4.5.4.
    #[serde(rename = "adgCode", skip_serializing_if = "Option::is_none")]
    pub adg_code: Option<String>,
    /// Unit of measure (≤50 chars, must be non-empty).
    pub unit: String,
    /// Primary discount amount (skip when no discount applies).
    #[serde(with = "dec_opt", skip_serializing_if = "Option::is_none", default)]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub discount: Option<Decimal>,
    /// Primary discount kind (skip when no discount applies).
    #[serde(rename = "discountType", skip_serializing_if = "Option::is_none")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<u32>"))]
    pub discount_kind: Option<DiscountKind>,
    /// Stacked secondary discount amount (skip when no discount applies).
    #[serde(
        rename = "additionalDiscount",
        with = "dec_opt",
        skip_serializing_if = "Option::is_none",
        default
    )]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub additional_discount: Option<Decimal>,
    /// Stacked secondary discount kind (skip when no discount applies).
    #[serde(
        rename = "additionalDiscountType",
        skip_serializing_if = "Option::is_none"
    )]
    #[cfg_attr(feature = "schema", schemars(with = "Option<u32>"))]
    pub additional_discount_kind: Option<DiscountKind>,
}

/// Op 4 response: fiscal data for a successfully-printed receipt.
///
/// Three fields (`qr`, `verification_number`, `emarks_count`) were added in spec revisions past
/// v0.5; they are marked `Option` with `serde(default)` so older HDM firmware still deserialises
/// without errors.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub struct ReceiptResponse {
    /// HDM-assigned receipt sequence number.
    pub rseq: i64,
    /// HDM registration number (unique per device).
    #[serde(default)]
    pub crn: String,
    /// HDM hardware serial number.
    #[serde(default)]
    pub sn: String,
    /// Taxpayer TIN.
    #[serde(default)]
    pub tin: String,
    /// Taxpayer legal name.
    #[serde(default)]
    pub taxpayer: String,
    /// Taxpayer registered address.
    #[serde(default)]
    pub address: String,
    /// Receipt timestamp (milliseconds since Unix epoch, Greenwich time).
    #[serde(default)]
    pub time: i64,
    /// Fiscal receipt number — the legally-binding identifier.
    #[serde(default)]
    pub fiscal: String,
    /// Lottery ticket number associated with the receipt.
    #[serde(default)]
    pub lottery: String,
    /// `0` = no prize, `1` = prize won. (Currently no longer used by the lottery system.)
    #[serde(default)]
    pub prize: u32,
    /// Total amount on the receipt.
    #[serde(default, with = "dec")]
    #[cfg_attr(feature = "schema", schemars(with = "f64"))]
    pub total: Decimal,
    /// Change due to the customer.
    #[serde(default, with = "dec")]
    #[cfg_attr(feature = "schema", schemars(with = "f64"))]
    pub change: Decimal,
    /// QR-code payload to render on the printed receipt. Added post-v0.5.
    #[serde(default)]
    pub qr: Option<String>,
    /// Number of eMark codes processed. Added post-v0.5. Documented as `string` in spec.
    #[serde(rename = "emarksCount", default)]
    pub emarks_count: Option<String>,
    /// Short alphanumeric verification number (≤13 chars) printed on the receipt. Added post-v0.5.
    #[serde(rename = "verificationNumber", default)]
    pub verification_number: Option<String>,
}

/// Op 5 request: reprint a copy of the operator's most recent receipt.
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PrintLastReceiptRequest {}

impl Operation for PrintLastReceiptRequest {
    const CODE: OperationCode = OperationCode::PrintLastReceipt;
    type Response = EmptyResponse;
}

/// Op 10 request: fetch the fiscal contents of a previously-issued receipt you intend to return.
///
/// This is a **read-only lookup**, not a refund. The original spec §4.5.6 is
/// "ՀԴՄ վերադարձվող կտրոնի ստացում" = *get the returnable receipt*. The spec describes it in section
/// §4.5.6, but its wire operation code is **10** per the operation-codes table (§4.4.1) — the section
/// number is not the operation code. It returns the receipt's items, amounts, eMarks and sale type
/// so a caller can construct the actual return via [`PrintReturnReceiptRequest`] (op 6). It registers
/// nothing.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct GetReturnableReceiptRequest {
    /// Number of the receipt to look up.
    #[serde(rename = "receiptId")]
    pub receipt_id: String,
    /// HDM registration number of the device that printed the original receipt.
    pub crn: String,
}

impl Operation for GetReturnableReceiptRequest {
    const CODE: OperationCode = OperationCode::GetReturnableReceipt;
    type Response = ReturnableReceiptResponse;
}

/// Op 10 response: the looked-up receipt's full fiscal contents.
///
/// **Unverified against hardware.** An earlier integration test sent this lookup to op 6 and got
/// vendor code 503 with an empty body, but op 6 is in fact the print-return code (this crate
/// previously had the two codes swapped), so that result does not characterise this lookup. The
/// lookup also keys on a server-side `Receipt_ID` the firmware never exposes (op 4 omits the `qr`
/// field entirely), so it may still be hard to satisfy in practice. This
/// struct is therefore modelled purely from spec §4.5.6, which is internally inconsistent: its
/// field table and the Code Block 7 example disagree (the example adds `type`, omits
/// `rseq`/`subType`/`refcrn`, and uses JSON numbers where the table says String). Fields follow the
/// Code Block 7 example — whose numeric types match what real firmware sends for op 4 — and are all
/// optional/lenient. The raw decrypted payload is logged at TRACE so the true shape can be
/// confirmed once a device ever returns one.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub struct ReturnableReceiptResponse {
    /// Receipt sequence number. The PDF field table calls this the return-receipt sequence number,
    /// but Code Block 7 omits it.
    #[serde(default)]
    pub rseq: Option<i64>,
    /// Cashier ID (`Գանձապահի ID`).
    #[serde(default)]
    pub cid: Option<i64>,
    /// Receipt registration/print time (ms since epoch, Greenwich).
    #[serde(default)]
    pub time: Option<i64>,
    /// Transaction type as the Code Block 7 example's `type` field (mirrors `sale_type`).
    #[serde(rename = "type", default)]
    pub kind: Option<i64>,
    /// Sale type: `0` sale, `2` return, `3` prepayment.
    #[serde(rename = "saleType", default)]
    pub sale_type: Option<i64>,
    /// Receipt sub-type: `1` simple, `2` itemised. (In the field table only; absent from the example.)
    #[serde(rename = "subType", default)]
    pub sub_type: Option<i64>,
    /// Department of a simple receipt.
    #[serde(default)]
    pub did: Option<i64>,
    /// Total amount.
    #[serde(default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub ta: Option<Decimal>,
    /// Cash paid.
    #[serde(default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub cash: Option<Decimal>,
    /// Card (cashless) paid.
    #[serde(default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub card: Option<Decimal>,
    /// Partial-payment amount.
    #[serde(default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub ppa: Option<Decimal>,
    /// Used prepayment amount.
    #[serde(default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub ppu: Option<Decimal>,
    /// Buyer TIN (8 digits) for a B2B receipt, or `null`.
    #[serde(rename = "pTin", default)]
    pub partner_tin: Option<String>,
    /// When this receipt is itself a return, the number of the receipt it returned (`ref`).
    #[serde(rename = "ref", default)]
    pub returned_receipt: Option<i64>,
    /// crn of the HDM that printed the returned receipt (set only for return-type receipts).
    #[serde(rename = "refcrn", default)]
    pub returned_crn: Option<String>,
    /// eMark codes of marked goods on the receipt.
    #[serde(rename = "eMarks", default)]
    pub e_marks: Vec<String>,
    /// Line items (empty for simple/prepayment receipts, where the spec sends `null`).
    #[serde(default)]
    pub totals: Vec<ReturnableReceiptItem>,
}

/// A single line item in a [`ReturnableReceiptResponse`] (`totals[]`). All fields optional/lenient
/// for the same reason as the parent — modelled from spec §4.5.6 Code Block 7, unverified.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub struct ReturnableReceiptItem {
    /// Product code (`gc`).
    #[serde(rename = "gc", default)]
    pub product_code: Option<String>,
    /// Product name (`gn`).
    #[serde(rename = "gn", default)]
    pub product_name: Option<String>,
    /// Quantity (`qty`).
    #[serde(default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub qty: Option<Decimal>,
    /// Unit price (`p`).
    #[serde(rename = "p", default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub price: Option<Decimal>,
    /// Unit of measure (`mu`).
    #[serde(rename = "mu", default)]
    pub unit: Option<String>,
    /// Row sequence number (`rpid`) — the handle used for per-item partial returns in op 6.
    #[serde(default)]
    pub rpid: Option<i64>,
    /// Primary discount (`dsc`).
    #[serde(rename = "dsc", default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub discount: Option<Decimal>,
    /// Proportional secondary discount (`adsc`).
    #[serde(rename = "adsc", default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub additional_discount: Option<Decimal>,
    /// Discount type (`dsct`).
    #[serde(rename = "dsct", default)]
    pub discount_kind: Option<i64>,
    /// Department (`did`).
    #[serde(default)]
    pub did: Option<i64>,
    /// Department VAT amount (`dt`).
    #[serde(rename = "dt", default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub vat_amount: Option<Decimal>,
    /// Department tax regime (`dtm`).
    #[serde(rename = "dtm", default)]
    pub tax_regime: Option<i64>,
    /// Line total excluding VAT (`t`).
    #[serde(rename = "t", default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub total_without_vat: Option<Decimal>,
    /// Line total including VAT (`tt`).
    #[serde(rename = "tt", default, with = "dec_opt")]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub total_with_vat: Option<Decimal>,
}

/// Op 6 request: print a return/refund receipt — the operation that actually registers a return.
///
/// With no amounts/items it returns the whole receipt; set the `*_for_return` amounts and/or
/// `return_item_list` for a partial return. The original spec §4.5.7 is
/// "ՀԴՄ վերադարձի կտրոնի տպում" = *print return receipt*. The spec describes it in section §4.5.7,
/// but its wire operation code is **6** per the operation-codes table (§4.4.1). The read-only lookup
/// of the receipt being returned is op 10, [`GetReturnableReceiptRequest`].
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PrintReturnReceiptRequest {
    /// HDM registration number of the device that printed the receipt.
    pub crn: String,
    /// Number of the receipt to be returned.
    #[serde(rename = "returnTicketId")]
    pub return_ticket_id: u64,
    /// Cash amount to return (only set for a partial return).
    #[serde(
        rename = "cashAmountForReturn",
        with = "dec_opt",
        skip_serializing_if = "Option::is_none",
        default
    )]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub cash_amount_for_return: Option<Decimal>,
    /// Card amount to return (only set for a partial return).
    #[serde(
        rename = "cardAmountForReturn",
        with = "dec_opt",
        skip_serializing_if = "Option::is_none",
        default
    )]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub card_amount_for_return: Option<Decimal>,
    /// Prepayment amount to return (only set for a partial return).
    #[serde(
        rename = "prePaymentAmountForReturn",
        with = "dec_opt",
        skip_serializing_if = "Option::is_none",
        default
    )]
    #[cfg_attr(feature = "schema", schemars(with = "Option<f64>"))]
    pub pre_payment_amount_for_return: Option<Decimal>,
    /// Acquirer RRN (12 chars).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rrn: Option<String>,
    /// Payment terminal ID (8 chars).
    #[serde(rename = "terminalId", skip_serializing_if = "Option::is_none")]
    pub terminal_id: Option<String>,
    /// eMark codes for marked goods.
    #[serde(rename = "eMarks", skip_serializing_if = "Vec::is_empty", default)]
    pub e_marks: Vec<String>,
    /// Per-item return list (only set when partially returning an itemised receipt).
    #[serde(
        rename = "returnItemList",
        skip_serializing_if = "Vec::is_empty",
        default
    )]
    pub return_item_list: Vec<ReturnItem>,
}

impl Operation for PrintReturnReceiptRequest {
    const CODE: OperationCode = OperationCode::PrintReturnReceipt;
    type Response = ReturnReceiptResponse;
}

/// Per-item entry in a partial-return request.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct ReturnItem {
    /// Row sequence number of the item being returned.
    pub rpid: i64,
    /// Quantity of this row's items to return.
    #[serde(with = "dec")]
    #[cfg_attr(feature = "schema", schemars(with = "f64"))]
    pub quantity: Decimal,
}

/// Op 6 response: full receipt details + return-specific timestamps.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub struct ReturnReceiptResponse {
    /// Receipt sequence number.
    pub rseq: i64,
    /// HDM registration number.
    #[serde(default)]
    pub crn: String,
    /// HDM hardware serial number.
    #[serde(default)]
    pub sn: String,
    /// Taxpayer TIN.
    #[serde(default)]
    pub tin: String,
    /// Taxpayer name.
    #[serde(default)]
    pub taxpayer: String,
    /// Taxpayer address.
    #[serde(default)]
    pub address: String,
    /// Original receipt timestamp (ms since epoch, Greenwich).
    #[serde(default)]
    pub time: i64,
    /// Return-receipt timestamp (ms since epoch, Greenwich).
    #[serde(default)]
    pub rtime: i64,
    /// Fiscal number.
    #[serde(default)]
    pub fiscal: String,
    /// Lottery number.
    #[serde(default)]
    pub lottery: String,
    /// Prize indicator (currently always 0).
    #[serde(default)]
    pub prize: u32,
    /// Total amount.
    #[serde(default, with = "dec")]
    #[cfg_attr(feature = "schema", schemars(with = "f64"))]
    pub total: Decimal,
    /// Change.
    #[serde(default, with = "dec")]
    #[cfg_attr(feature = "schema", schemars(with = "f64"))]
    pub change: Decimal,
    /// Number of registered marks.
    #[serde(rename = "emarksCount", default)]
    pub emarks_count: Option<String>,
    /// Short verification number printed on the receipt.
    #[serde(rename = "verificationNumber", default)]
    pub verification_number: Option<String>,
}