namespace DocumentOperator.Domain.ValueObjects;

/// <summary>
/// Represents Swiss QR Code data according to Swiss QR Bill Standard 2.0.
/// Immutable value object containing all fields from a Swiss QR payment part.
/// </summary>
public sealed record SwissQrCodeData
{
    /// <summary>
    /// QR type - always "SPC" for Swiss Payment Code
    /// </summary>
    public required string QrType { get; init; }

    /// <summary>
    /// Version of the Swiss QR Code standard (e.g., "0200" for version 2.0)
    /// </summary>
    public required string Version { get; init; }

    /// <summary>
    /// Character set code (always "1" for UTF-8)
    /// </summary>
    public required string CodingType { get; init; }

    /// <summary>
    /// IBAN of the creditor (payee)
    /// </summary>
    public required string Iban { get; init; }

    /// <summary>
    /// Creditor (payee) information
    /// </summary>
    public required AddressData Creditor { get; init; }

    /// <summary>
    /// Ultimate creditor information (optional)
    /// </summary>
    public AddressData? UltimateCreditor { get; init; }

    /// <summary>
    /// Payment amount (null if not specified)
    /// </summary>
    public decimal? Amount { get; init; }

    /// <summary>
    /// Currency code (CHF or EUR)
    /// </summary>
    public required string Currency { get; init; }

    /// <summary>
    /// Ultimate debtor (payer) information (optional)
    /// </summary>
    public AddressData? UltimateDebtor { get; init; }

    /// <summary>
    /// Reference type (QRR, SCOR, or NON)
    /// </summary>
    public required string ReferenceType { get; init; }

    /// <summary>
    /// Payment reference (format depends on ReferenceType)
    /// </summary>
    public string? Reference { get; init; }

    /// <summary>
    /// Unstructured message (max 140 characters)
    /// </summary>
    public string? UnstructuredMessage { get; init; }

    /// <summary>
    /// Bill information (structured data for automated processing)
    /// </summary>
    public string? BillInformation { get; init; }

    /// <summary>
    /// Alternative procedure parameters (up to 2 entries)
    /// </summary>
    public IReadOnlyList<string>? AlternativeProcedureParameters { get; init; }
}

/// <summary>
/// Represents address data in Swiss QR Code (creditor or debtor)
/// </summary>
public sealed record AddressData
{
    /// <summary>
    /// Address type: "S" for structured, "K" for combined
    /// </summary>
    public required string AddressType { get; init; }

    /// <summary>
    /// Name of person or company
    /// </summary>
    public required string Name { get; init; }

    /// <summary>
    /// Street name (structured address only)
    /// </summary>
    public string? Street { get; init; }

    /// <summary>
    /// Building number (structured address only)
    /// </summary>
    public string? BuildingNumber { get; init; }

    /// <summary>
    /// Address line 1 (combined address only)
    /// </summary>
    public string? AddressLine1 { get; init; }

    /// <summary>
    /// Address line 2 (combined address only)
    /// </summary>
    public string? AddressLine2 { get; init; }

    /// <summary>
    /// Postal code
    /// </summary>
    public required string PostalCode { get; init; }

    /// <summary>
    /// City/town name
    /// </summary>
    public required string City { get; init; }

    /// <summary>
    /// Two-letter country code (ISO 3166-1 alpha-2)
    /// </summary>
    public required string Country { get; init; }
}
