#nullable enable
namespace Baya.Application.Models.Bnpl;

/// <summary>
/// The facts eligibility/initiate need for an <c>accepted_awaiting_payment</c> booking request: the owning
/// customer (tenancy) + their user id + mobile (for the provider eligibility/token call), the request status +
/// frozen payment window, and the gross to finance (variant price × session count — the same figure b9 freezes
/// onto the booking on capture). Money is IRR <c>long</c>.
/// </summary>
public record BnplOrderContext(
    long RequestId,
    long CustomerId,
    int CustomerUserId,
    string CustomerMobile,
    string Status,
    System.DateTime? PaymentDeadlineAt,
    long GrossIrr);

/// <summary>The eligibility result the client shows (or falls back to card on): the outcome, the plan summary,
/// and whether the client should offer the "pay with installments" option.</summary>
public record BnplEligibilityDto(
    string EligibilityStatus,
    bool IsEligible,
    int InstallmentCount,
    string PlanSummary,
    string? CreditCeilingIrr);

/// <summary>The result of starting a BNPL order: the token + provider redirect the client hands off to, plus the
/// row + status. No money crosses back here — it is the request's frozen gross.</summary>
public record InitiateBnplResult(
    long BnplTransactionId,
    long PaymentTransactionId,
    string Status,
    string ExternalPaymentToken,
    string RedirectUrl);

/// <summary>The admin/customer BNPL order view: status, the money split (gross/net/commission), the non-instant
/// settlement time, and the revert audit. Money crosses the wire as digit strings; <c>settled_at</c> is nullable.</summary>
public record BnplOrderStatusDto(
    long Id,
    long PaymentTransactionId,
    long? BookingId,
    string ProviderCode,
    string Status,
    string? EligibilityStatus,
    string OrderAmountIrr,
    string? SettledAmountIrr,
    string? BnplCommissionIrr,
    string Currency,
    int InstallmentCount,
    System.DateTime? SettledAt,
    string? RevertTransactionId,
    string? RevertedAmountIrr,
    System.DateTime? RevertedAt,
    string? ProviderCommissionReversedAmount,
    string? RefundChannel,
    System.DateOnly? ExpectedCustomerRefundEta,
    System.DateTimeOffset CreatedAt);

/// <summary>The tenancy envelope for the customer BNPL-order read: the owning customer's user id (compared to
/// <c>ICurrentUser</c>) plus the DTO. A cross-customer access is a clean not-found, never a leak.</summary>
public record BnplOrderStatusProjection(int CustomerUserId, BnplOrderStatusDto Order);

/// <summary>The outcome of ingesting a BNPL provider callback — the terminal processing status + whether it was a
/// deduplicated replay. The endpoint is always success (at-least-once tolerant).</summary>
public record BnplCallbackResult(string ProcessingStatus, bool Duplicate);

/// <summary>What <c>RevertBnplOrderCommand</c> returns — the reverted order, the created refund, the provider
/// revert reference and the async customer cash-back ETA (~7–10 business days).</summary>
public record RevertBnplResult(
    long BnplTransactionId,
    long RefundId,
    string Status,
    string? RevertTransactionId,
    string RevertedAmountIrr,
    System.DateOnly? ExpectedCustomerRefundEta);
