use serde::{Deserialize, Serialize};

use crate::{
    Adnotacje, CorrectionData, DaneKontaktowe, DodatkowyOpis, FakturaZaliczkowaRef,
    InvoiceLineItem, Platnosc, Podmiot3Info, PodmiotUpowaznionyInfo, Rozliczenie, Stopka,
    VatRateInfo, WarunkiTransakcji, Zalacznik, ZaliczkaCzesciowa, ZamowienieData,
};

/// AI-extracted invoice data from PDFs/images.
///
/// All fields are `Option<T>` (except `raw_text` and some legacy bool/Vec fields)
/// so that partial extraction results can be represented.
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[derive(Debug, Default, Clone, Deserialize, Serialize)]
pub struct InvoiceDraftData {
    // ====== Metadata (application-level) ======
    #[serde(default)]
    pub id: Option<String>,
    #[serde(default, rename = "ksefReference")]
    pub ksef_reference: Option<String>,
    #[serde(default, rename = "createdAt")]
    pub created_at: Option<String>,
    #[serde(default, rename = "updatedAt")]
    pub updated_at: Option<String>,

    // ====== Naglowek (TNaglowek) ======
    #[serde(default, rename = "formCode", skip_serializing_if = "Option::is_none")]
    pub form_code: Option<String>,
    #[serde(
        default,
        rename = "formSystemCode",
        skip_serializing_if = "Option::is_none"
    )]
    pub form_system_code: Option<String>,
    #[serde(
        default,
        rename = "formSchemaVersion",
        skip_serializing_if = "Option::is_none"
    )]
    pub form_schema_version: Option<String>,
    #[serde(
        default,
        rename = "formVariant",
        skip_serializing_if = "Option::is_none"
    )]
    pub form_variant: Option<u8>,
    #[serde(
        default,
        rename = "creationDate",
        skip_serializing_if = "Option::is_none"
    )]
    pub creation_date: Option<String>,
    #[serde(
        default,
        rename = "systemInfo",
        skip_serializing_if = "Option::is_none"
    )]
    pub system_info: Option<String>,

    // ====== Podmiot1 (issuer / seller) ======
    #[serde(default, rename = "issuerName")]
    pub issuer_name: Option<String>,
    #[serde(default, rename = "issuerNip")]
    pub issuer_nip: Option<String>,
    #[serde(
        default,
        rename = "issuerAddress",
        skip_serializing_if = "Option::is_none"
    )]
    pub issuer_address: Option<String>,
    #[serde(
        default,
        rename = "issuerPostalCode",
        skip_serializing_if = "Option::is_none"
    )]
    pub issuer_postal_code: Option<String>,
    #[serde(
        default,
        rename = "issuerCity",
        skip_serializing_if = "Option::is_none"
    )]
    pub issuer_city: Option<String>,
    #[serde(
        default,
        rename = "issuerCountry",
        skip_serializing_if = "Option::is_none"
    )]
    pub issuer_country: Option<String>,
    #[serde(default, rename = "issuerKrs", skip_serializing_if = "Option::is_none")]
    pub issuer_krs: Option<String>,
    #[serde(
        default,
        rename = "issuerRegon",
        skip_serializing_if = "Option::is_none"
    )]
    pub issuer_regon: Option<String>,
    #[serde(
        default,
        rename = "issuerTaxPrefix",
        skip_serializing_if = "Option::is_none"
    )]
    pub issuer_tax_prefix: Option<String>,
    #[serde(
        default,
        rename = "issuerNrEori",
        skip_serializing_if = "Option::is_none"
    )]
    pub issuer_nr_eori: Option<String>,
    #[serde(
        default,
        rename = "issuerTaxStatus",
        skip_serializing_if = "Option::is_none"
    )]
    pub issuer_tax_status: Option<u8>,
    #[serde(
        default,
        rename = "sellerEmail",
        skip_serializing_if = "Option::is_none"
    )]
    pub seller_email: Option<String>,
    #[serde(
        default,
        rename = "sellerPhone",
        skip_serializing_if = "Option::is_none"
    )]
    pub seller_phone: Option<String>,
    #[serde(
        default,
        rename = "issuerCorrespondenceAddress",
        skip_serializing_if = "Option::is_none"
    )]
    pub issuer_correspondence_address: Option<String>,
    #[serde(
        default,
        rename = "issuerContacts",
        skip_serializing_if = "Option::is_none"
    )]
    pub issuer_contacts: Option<Vec<DaneKontaktowe>>,

    // ====== Podmiot2 (recipient / buyer) ======
    #[serde(default, rename = "recipientName")]
    pub recipient_name: Option<String>,
    #[serde(default, rename = "recipientNip")]
    pub recipient_nip: Option<String>,
    #[serde(
        default,
        rename = "recipientAddress",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_address: Option<String>,
    #[serde(
        default,
        rename = "recipientPostalCode",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_postal_code: Option<String>,
    #[serde(
        default,
        rename = "recipientCity",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_city: Option<String>,
    #[serde(
        default,
        rename = "recipientCountry",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_country: Option<String>,
    #[serde(
        default,
        rename = "recipientKrs",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_krs: Option<String>,
    #[serde(
        default,
        rename = "recipientRegon",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_regon: Option<String>,
    #[serde(
        default,
        rename = "recipientNrEori",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_nr_eori: Option<String>,
    #[serde(
        default,
        rename = "recipientKodUe",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_kod_ue: Option<String>,
    #[serde(
        default,
        rename = "recipientNrVatUe",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_nr_vat_ue: Option<String>,
    #[serde(
        default,
        rename = "recipientKodKraju",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_kod_kraju: Option<String>,
    #[serde(
        default,
        rename = "recipientNrId",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_nr_id: Option<String>,
    #[serde(
        default,
        rename = "recipientBrakId",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_brak_id: Option<u8>,
    #[serde(
        default,
        rename = "buyerEmail",
        skip_serializing_if = "Option::is_none"
    )]
    pub buyer_email: Option<String>,
    #[serde(
        default,
        rename = "buyerPhone",
        skip_serializing_if = "Option::is_none"
    )]
    pub buyer_phone: Option<String>,
    #[serde(
        default,
        rename = "buyerClientNumber",
        skip_serializing_if = "Option::is_none"
    )]
    pub buyer_client_number: Option<String>,
    #[serde(
        default,
        rename = "buyerIdNabywcy",
        skip_serializing_if = "Option::is_none"
    )]
    pub buyer_id_nabywcy: Option<String>,
    #[serde(
        default,
        rename = "recipientCorrespondenceAddress",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_correspondence_address: Option<String>,
    #[serde(
        default,
        rename = "recipientContacts",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_contacts: Option<Vec<DaneKontaktowe>>,
    #[serde(
        default,
        rename = "recipientJst",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_jst: Option<u8>,
    #[serde(
        default,
        rename = "recipientGv",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_gv: Option<u8>,

    // ====== Podmiot3 ======
    #[serde(default, rename = "podmiot3", skip_serializing_if = "Option::is_none")]
    pub podmiot3: Option<Vec<Podmiot3Info>>,

    // ====== PodmiotUpowazniony ======
    #[serde(
        default,
        rename = "podmiotUpowazniony",
        skip_serializing_if = "Option::is_none"
    )]
    pub podmiot_upowazniony: Option<PodmiotUpowaznionyInfo>,

    // ====== Fa section ======
    #[serde(default)]
    pub currency: Option<String>,
    #[serde(default, rename = "invoiceNumber")]
    pub invoice_number: Option<String>,
    #[serde(default, rename = "invoiceType")]
    pub invoice_type: Option<String>,
    #[serde(default, rename = "issueDate")]
    pub issue_date: Option<String>,
    #[serde(
        default,
        rename = "issuePlace",
        skip_serializing_if = "Option::is_none"
    )]
    pub issue_place: Option<String>,
    #[serde(default, rename = "wz", skip_serializing_if = "Option::is_none")]
    pub wz: Option<Vec<String>>,
    #[serde(default, rename = "saleDate")]
    pub sale_date: Option<String>,
    #[serde(
        default,
        rename = "serviceDate",
        skip_serializing_if = "Option::is_none"
    )]
    pub service_date: Option<String>,
    #[serde(
        default,
        rename = "billingPeriodFrom",
        skip_serializing_if = "Option::is_none"
    )]
    pub billing_period_from: Option<String>,
    #[serde(
        default,
        rename = "billingPeriodTo",
        skip_serializing_if = "Option::is_none"
    )]
    pub billing_period_to: Option<String>,

    // --- VAT rate summaries (P_13_x / P_14_x) ---
    #[serde(default, rename = "p131", skip_serializing_if = "Option::is_none")]
    pub p_13_1: Option<f64>,
    #[serde(default, rename = "p141", skip_serializing_if = "Option::is_none")]
    pub p_14_1: Option<f64>,
    #[serde(default, rename = "p141w", skip_serializing_if = "Option::is_none")]
    pub p_14_1w: Option<f64>,
    #[serde(default, rename = "p132", skip_serializing_if = "Option::is_none")]
    pub p_13_2: Option<f64>,
    #[serde(default, rename = "p142", skip_serializing_if = "Option::is_none")]
    pub p_14_2: Option<f64>,
    #[serde(default, rename = "p142w", skip_serializing_if = "Option::is_none")]
    pub p_14_2w: Option<f64>,
    #[serde(default, rename = "p133", skip_serializing_if = "Option::is_none")]
    pub p_13_3: Option<f64>,
    #[serde(default, rename = "p143", skip_serializing_if = "Option::is_none")]
    pub p_14_3: Option<f64>,
    #[serde(default, rename = "p143w", skip_serializing_if = "Option::is_none")]
    pub p_14_3w: Option<f64>,
    #[serde(default, rename = "p134", skip_serializing_if = "Option::is_none")]
    pub p_13_4: Option<f64>,
    #[serde(default, rename = "p144", skip_serializing_if = "Option::is_none")]
    pub p_14_4: Option<f64>,
    #[serde(default, rename = "p144w", skip_serializing_if = "Option::is_none")]
    pub p_14_4w: Option<f64>,
    #[serde(default, rename = "p135", skip_serializing_if = "Option::is_none")]
    pub p_13_5: Option<f64>,
    #[serde(default, rename = "p145", skip_serializing_if = "Option::is_none")]
    pub p_14_5: Option<f64>,
    #[serde(default, rename = "p1361", skip_serializing_if = "Option::is_none")]
    pub p_13_6_1: Option<f64>,
    #[serde(default, rename = "p1362", skip_serializing_if = "Option::is_none")]
    pub p_13_6_2: Option<f64>,
    #[serde(default, rename = "p1363", skip_serializing_if = "Option::is_none")]
    pub p_13_6_3: Option<f64>,
    #[serde(default, rename = "p137", skip_serializing_if = "Option::is_none")]
    pub p_13_7: Option<f64>,
    #[serde(default, rename = "p138", skip_serializing_if = "Option::is_none")]
    pub p_13_8: Option<f64>,
    #[serde(default, rename = "p139", skip_serializing_if = "Option::is_none")]
    pub p_13_9: Option<f64>,
    #[serde(default, rename = "p1310", skip_serializing_if = "Option::is_none")]
    pub p_13_10: Option<f64>,
    #[serde(default, rename = "p1311", skip_serializing_if = "Option::is_none")]
    pub p_13_11: Option<f64>,

    #[serde(default, rename = "vatRates", skip_serializing_if = "Option::is_none")]
    pub vat_rates: Option<Vec<VatRateInfo>>,

    #[serde(default, rename = "grossAmount")]
    pub gross_amount: Option<f64>,
    #[serde(default, rename = "netAmount")]
    pub net_amount: Option<f64>,
    #[serde(default, rename = "taxAmount")]
    pub tax_amount: Option<f64>,
    #[serde(
        default,
        rename = "exchangeRateAdvance",
        skip_serializing_if = "Option::is_none"
    )]
    pub exchange_rate_advance: Option<f64>,
    #[serde(
        default,
        rename = "exchangeRate",
        skip_serializing_if = "Option::is_none"
    )]
    pub exchange_rate: Option<f64>,

    // ====== Adnotacje ======
    #[serde(default, rename = "adnotacje", skip_serializing_if = "Option::is_none")]
    pub adnotacje: Option<Adnotacje>,
    #[serde(
        default,
        rename = "annotationSplitPayment",
        skip_serializing_if = "Option::is_none"
    )]
    pub annotation_split_payment: Option<bool>,
    #[serde(
        default,
        rename = "annotationReverseCharge",
        skip_serializing_if = "Option::is_none"
    )]
    pub annotation_reverse_charge: Option<bool>,
    #[serde(
        default,
        rename = "annotationSelfBilling",
        skip_serializing_if = "Option::is_none"
    )]
    pub annotation_self_billing: Option<bool>,
    #[serde(
        default,
        rename = "annotationCashMethod",
        skip_serializing_if = "Option::is_none"
    )]
    pub annotation_cash_method: Option<bool>,
    #[serde(
        default,
        rename = "taxExemptionBasis",
        skip_serializing_if = "Option::is_none"
    )]
    pub tax_exemption_basis: Option<String>,

    // ====== RodzajFaktury ======
    #[serde(
        default,
        rename = "invoiceKind",
        skip_serializing_if = "Option::is_none"
    )]
    pub invoice_kind: Option<String>,
    #[serde(
        default,
        rename = "rodzajFaktury",
        skip_serializing_if = "Option::is_none"
    )]
    pub rodzaj_faktury: Option<String>,

    // ====== Correction data ======
    #[serde(
        default,
        rename = "correctionReason",
        skip_serializing_if = "Option::is_none"
    )]
    pub correction_reason: Option<String>,
    #[serde(
        default,
        rename = "correctionType",
        skip_serializing_if = "Option::is_none"
    )]
    pub correction_type: Option<u8>,
    #[serde(
        default,
        rename = "correctedInvoiceNumber",
        skip_serializing_if = "Option::is_none"
    )]
    pub corrected_invoice_number: Option<String>,
    #[serde(
        default,
        rename = "correctedInvoiceDate",
        skip_serializing_if = "Option::is_none"
    )]
    pub corrected_invoice_date: Option<String>,
    #[serde(
        default,
        rename = "correctedKsefNumber",
        skip_serializing_if = "Option::is_none"
    )]
    pub corrected_ksef_number: Option<String>,
    #[serde(default, rename = "nrKsefN", skip_serializing_if = "Option::is_none")]
    pub nr_ksef_n: Option<String>,
    #[serde(
        default,
        rename = "correctionData",
        skip_serializing_if = "Option::is_none"
    )]
    pub correction_data: Option<CorrectionData>,

    // ====== ZaliczkaCzesciowa ======
    #[serde(
        default,
        rename = "zaliczkiCzesciowe",
        skip_serializing_if = "Option::is_none"
    )]
    pub zaliczki_czesciowe: Option<Vec<ZaliczkaCzesciowa>>,

    // ====== FP, TP ======
    #[serde(default, rename = "fp", skip_serializing_if = "Option::is_none")]
    pub fp: Option<u8>,
    #[serde(default, rename = "tp", skip_serializing_if = "Option::is_none")]
    pub tp: Option<u8>,

    // ====== DodatkowyOpis ======
    #[serde(
        default,
        rename = "dodatkowyOpis",
        skip_serializing_if = "Option::is_none"
    )]
    pub dodatkowy_opis: Option<Vec<DodatkowyOpis>>,
    #[serde(
        default,
        rename = "additionalDescriptions",
        skip_serializing_if = "Option::is_none"
    )]
    pub additional_descriptions: Option<Vec<DodatkowyOpis>>,

    // ====== FakturaZaliczkowa refs ======
    #[serde(
        default,
        rename = "fakturaZaliczkowaRef",
        skip_serializing_if = "Option::is_none"
    )]
    pub faktura_zaliczkowa_ref: Option<Vec<FakturaZaliczkowaRef>>,

    /// Zwrot akcyzy.
    #[serde(
        default,
        rename = "zwrotAkcyzy",
        skip_serializing_if = "Option::is_none"
    )]
    pub zwrot_akcyzy: Option<u8>,

    // ====== FaWiersz (line items) ======
    #[serde(default, rename = "lineItems", skip_serializing_if = "Option::is_none")]
    pub line_items: Option<Vec<InvoiceLineItem>>,

    // ====== Rozliczenie ======
    #[serde(
        default,
        rename = "rozliczenie",
        skip_serializing_if = "Option::is_none"
    )]
    pub rozliczenie: Option<Rozliczenie>,
    #[serde(
        default,
        rename = "settlement",
        skip_serializing_if = "Option::is_none"
    )]
    pub settlement: Option<String>,

    // ====== Platnosc ======
    #[serde(default, rename = "platnosc", skip_serializing_if = "Option::is_none")]
    pub platnosc: Option<Platnosc>,
    #[serde(
        default,
        rename = "paymentMethod",
        skip_serializing_if = "Option::is_none"
    )]
    pub payment_method: Option<String>,
    #[serde(
        default,
        rename = "paymentDueDate",
        skip_serializing_if = "Option::is_none"
    )]
    pub payment_due_date: Option<String>,
    #[serde(
        default,
        rename = "paymentDate",
        skip_serializing_if = "Option::is_none"
    )]
    pub payment_date: Option<String>,
    #[serde(default, rename = "paidDate", skip_serializing_if = "Option::is_none")]
    pub paid_date: Option<String>,
    #[serde(default, rename = "isPaid", skip_serializing_if = "Option::is_none")]
    pub is_paid: Option<bool>,
    #[serde(
        default,
        rename = "bankAccount",
        skip_serializing_if = "Option::is_none"
    )]
    pub bank_account: Option<String>,
    #[serde(default, rename = "bankName", skip_serializing_if = "Option::is_none")]
    pub bank_name: Option<String>,
    #[serde(default, rename = "bankSwift", skip_serializing_if = "Option::is_none")]
    pub bank_swift: Option<String>,
    #[serde(
        default,
        rename = "bankDescription",
        skip_serializing_if = "Option::is_none"
    )]
    pub bank_description: Option<String>,
    #[serde(
        default,
        rename = "bankOwnAccount",
        skip_serializing_if = "Option::is_none"
    )]
    pub bank_own_account: Option<String>,
    #[serde(
        default,
        rename = "discountAmount",
        skip_serializing_if = "Option::is_none"
    )]
    pub discount_amount: Option<f64>,

    // ====== WarunkiTransakcji ======
    #[serde(
        default,
        rename = "warunkiTransakcji",
        skip_serializing_if = "Option::is_none"
    )]
    pub warunki_transakcji: Option<WarunkiTransakcji>,
    #[serde(
        default,
        rename = "deliveryTerms",
        skip_serializing_if = "Option::is_none"
    )]
    pub delivery_terms: Option<String>,
    #[serde(
        default,
        rename = "orderNumber",
        skip_serializing_if = "Option::is_none"
    )]
    pub order_number: Option<String>,
    #[serde(
        default,
        rename = "orderNumbers",
        skip_serializing_if = "Option::is_none"
    )]
    pub order_numbers: Option<Vec<String>>,

    // ====== Zamowienie ======
    #[serde(
        default,
        rename = "zamowienie",
        skip_serializing_if = "Option::is_none"
    )]
    pub zamowienie: Option<ZamowienieData>,

    // ====== Stopka ======
    #[serde(default, rename = "stopka", skip_serializing_if = "Option::is_none")]
    pub stopka: Option<Stopka>,
    #[serde(
        default,
        rename = "footerText",
        skip_serializing_if = "Option::is_none"
    )]
    pub footer_text: Option<String>,

    // ====== Zalacznik ======
    #[serde(default, rename = "zalacznik", skip_serializing_if = "Option::is_none")]
    pub zalacznik: Option<Zalacznik>,

    // ====== App-level/KSeF metadata ======
    #[serde(
        default,
        rename = "ksefNumber",
        skip_serializing_if = "Option::is_none"
    )]
    pub ksef_number: Option<String>,
    #[serde(
        default,
        rename = "processingDate",
        skip_serializing_if = "Option::is_none"
    )]
    pub processing_date: Option<String>,
    #[serde(
        default,
        rename = "sessionRef",
        skip_serializing_if = "Option::is_none"
    )]
    pub session_ref: Option<String>,
    #[serde(
        default,
        rename = "upoAvailable",
        skip_serializing_if = "Option::is_none"
    )]
    pub upo_available: Option<bool>,
    #[serde(
        default,
        rename = "upoReference",
        skip_serializing_if = "Option::is_none"
    )]
    pub upo_reference: Option<String>,
    #[serde(default, rename = "qrCodeUrl", skip_serializing_if = "Option::is_none")]
    pub qr_code_url: Option<String>,
    #[serde(
        default,
        rename = "isSelfBilling",
        skip_serializing_if = "Option::is_none"
    )]
    pub is_self_billing_opt: Option<bool>,
    #[serde(
        default,
        rename = "isSimplified",
        skip_serializing_if = "Option::is_none"
    )]
    pub is_simplified: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub bdo: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub notes: Option<String>,
    #[serde(default, rename = "p425", skip_serializing_if = "Option::is_none")]
    pub p_42_5: Option<u8>,

    // ====== Legacy alias fields ======
    /// Alias for seller_email.
    #[serde(
        default,
        rename = "issuerEmail",
        skip_serializing_if = "Option::is_none"
    )]
    pub issuer_email: Option<String>,
    /// Alias for buyer_email.
    #[serde(
        default,
        rename = "recipientEmail",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_email: Option<String>,
    /// Alias for buyer_client_number.
    #[serde(
        default,
        rename = "recipientClientNumber",
        skip_serializing_if = "Option::is_none"
    )]
    pub recipient_client_number: Option<String>,

    // ====== Podmiot3 shorthand ======
    #[serde(
        default,
        rename = "odbiorcaName",
        skip_serializing_if = "Option::is_none"
    )]
    pub odbiorca_name: Option<String>,
    #[serde(
        default,
        rename = "odbiorcaNip",
        skip_serializing_if = "Option::is_none"
    )]
    pub odbiorca_nip: Option<String>,
    #[serde(
        default,
        rename = "odbiorcaAddress",
        skip_serializing_if = "Option::is_none"
    )]
    pub odbiorca_address: Option<String>,

    // ====== PLN equivalents ======
    #[serde(
        default,
        rename = "netAmountPln",
        skip_serializing_if = "Option::is_none"
    )]
    pub net_amount_pln: Option<f64>,
    #[serde(
        default,
        rename = "taxAmountPln",
        skip_serializing_if = "Option::is_none"
    )]
    pub tax_amount_pln: Option<f64>,
    #[serde(
        default,
        rename = "grossAmountPln",
        skip_serializing_if = "Option::is_none"
    )]
    pub gross_amount_pln: Option<f64>,

    #[serde(
        default,
        rename = "exchangeRateDate",
        skip_serializing_if = "Option::is_none"
    )]
    pub exchange_rate_date: Option<String>,

    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub krs: Option<String>,

    // ====== Legacy bool fields ======
    #[serde(default, rename = "isCashMethod")]
    pub is_cash_method: bool,
    #[serde(default, rename = "isReverseCharge")]
    pub is_reverse_charge: bool,
    #[serde(default, rename = "isSplitPayment")]
    pub is_split_payment: bool,
    #[serde(default, rename = "taxExemption")]
    pub tax_exemption: bool,
    #[serde(default, rename = "isTriangular")]
    pub is_triangular: bool,
    #[serde(default, rename = "isMargin")]
    pub is_margin: bool,

    // ====== Legacy Vec fields ======
    #[serde(default, rename = "deliveryNotes")]
    pub delivery_notes: Vec<String>,

    // ====== raw_text — MUST be last ======
    #[serde(default, rename = "rawText")]
    pub raw_text: String,
}
