using System.Text.Json.Serialization;

namespace Inspectron.Epson.PrintServer.Printers.Utils.MoneyReturnReceipt;

/// <summary>
/// Data model for a refund / credit note ("money return") receipt.
/// Matches the refund payload (see money_return_receipt_data.json / data (1).json):
/// restaurant header info, original transaction reference, refunded items and the
/// per-rate VAT breakdown. Timestamps are Unix epoch milliseconds.
/// </summary>
public class MoneyReturnReceipt
{
    /// <summary>Base64-encoded restaurant logo (optional). Rendered by the print pipeline, not the text converter.</summary>
    public string? RestaurantLogo { get; set; }

    public string RestaurantName { get; set; }
    public string RestaurantPhoneNumber { get; set; }
    public string RestaurantAddressLine1 { get; set; }
    public string RestaurantAddressLine2 { get; set; }
    public string RestaurantWebsite { get; set; }

    /// <summary>VAT registration number. Note the misspelled JSON key ("Restauant...").</summary>
    [JsonPropertyName("RestauantVATNumber")]
    public string? RestaurantVatNumber { get; set; }

    public string ThanksMessage { get; set; }

    /// <summary>When true the sale is not subject to VAT and the tax table is replaced by a note.</summary>
    public bool NoVAT { get; set; }

    public long? RefundReceiptId { get; set; }

    /// <summary>Credit note number (shown as "Credit note No. {RefundNumber}").</summary>
    public long RefundNumber { get; set; }

    /// <summary>When the refund was issued, as Unix epoch milliseconds.</summary>
    public long RefundTimestamp { get; set; }

    /// <summary>Number of the original transaction/invoice being refunded ("Orig. invoice No.").</summary>
    public long OriginalTransactionNumber { get; set; }

    /// <summary>When the original payment was made, as Unix epoch milliseconds ("Orig. date").</summary>
    public long OriginalPaymentTimestamp { get; set; }

    /// <summary>Method the original payment was made with (e.g. "Cash").</summary>
    public string OriginalPaymentMethod { get; set; }

    public string Currency { get; set; }

    /// <summary>Refund type, e.g. "Full" or "Partial" (rendered as "Full refund").</summary>
    public string RefundType { get; set; }

    /// <summary>Tip amount included in the refund. Shown as "incl. tip" when non-zero.</summary>
    public decimal TipAmount { get; set; }

    public List<RefundedItem> RefundedItems { get; set; } = new List<RefundedItem>();

    /// <summary>Total refunded amount (positive). Rendered negative on the receipt.</summary>
    public decimal RefundedAmount { get; set; }

    /// <summary>Standard-rate VAT bucket. Note the misspelled JSON key ("Standart...").</summary>
    [JsonPropertyName("StandartRate")]
    public TaxRateBreakdown StandardRate { get; set; }

    public TaxRateBreakdown ReducedRate { get; set; }

    public TaxRateBreakdown SpecialRateForAccommodation { get; set; }

    /// <summary>Method the refund was paid out with (e.g. "Cash").</summary>
    public string RefundPaymentMethod { get; set; }

    public string TerminalReceiptData { get; set; }
    public string WebPaymentReceiptData { get; set; }
}

public class RefundedItem
{
    public string Name { get; set; }
    public string Size { get; set; }
    public int Quantity { get; set; }
    public decimal Price { get; set; }
    public string TaxAbbr { get; set; }
}

public class TaxRateBreakdown
{
    public decimal Rate { get; set; }

    /// <summary>Gross amount at this rate.</summary>
    public decimal TotalAmount { get; set; }

    /// <summary>Net amount at this rate.</summary>
    public decimal TotalAmountNetto { get; set; }

    /// <summary>Tax amount at this rate.</summary>
    public decimal TotalAmountTax { get; set; }
}
