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

/// <summary>
/// Everything <c>CreateRefundCommand</c> needs in one read to decompose, pick the channel and enforce
/// <c>Σ refunded ≤ captured</c>: the booking's frozen three-amount split, the b9 cancellation snapshot (never
/// re-resolved live), and the captured transaction it reverses. Money is IRR <c>long</c>.
/// </summary>
public record RefundMoneyContext(
    long BookingId,
    long CustomerId,
    int CustomerUserId,
    long NurseId,
    long GrossPriceIrr,
    long CommissionIrr,
    long PayoutIrr,
    string? CancellationPolicyCode,
    decimal? CancellationRefundPercentage,
    long? RefundableAmountIrr,
    long PaymentTransactionId,
    string? GatewayReferenceCode,
    long CapturedAmount,
    string GatewayType);

/// <summary>The admin refund worklist row — channel, decomposed legs, status, policy snapshot and the BNPL ETA.
/// Money crosses the wire as digit strings.</summary>
public record RefundListItemDto(
    long Id,
    long BookingId,
    long PaymentTransactionId,
    string Amount,
    string PlatformFeeRefundedIrr,
    string NursePayoutRefundedIrr,
    string RefundChannel,
    string Status,
    decimal RefundPercentage,
    string? ReasonCategory,
    string? CancellationPolicyCode,
    decimal? RefundPercentageApplied,
    DateOnly? ExpectedCustomerRefundEta,
    string? GatewayRefundReference,
    string? ExternalRevertReference,
    DateTime? ProcessedAt,
    DateTimeOffset CreatedAt);

/// <summary>The customer-facing status of their own refund — the reference is masked, money is a digit string,
/// and the BNPL 7–10-business-day window is surfaced so the UI can show "on its way, ~N days". The fee-leg
/// decomposition (<c>platformFeeRefundedIrr</c>/<c>nursePayoutRefundedIrr</c>) + policy snapshot let the UI
/// render the transparency split without re-deriving it.</summary>
public record RefundStatusDto(
    long Id,
    long BookingId,
    string Status,
    string RefundChannel,
    string Amount,
    DateOnly? ExpectedCustomerRefundEta,
    string? Reference,
    string PlatformFeeRefundedIrr,
    string NursePayoutRefundedIrr,
    decimal? RefundPercentageApplied,
    string? CancellationPolicyCode,
    DateTimeOffset CreatedAt,
    DateTime? CompletedAt);

/// <summary>The tenancy envelope for the customer refund-status 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 RefundStatusProjection(int CustomerUserId, RefundStatusDto Refund);

/// <summary>What the settlement transition commands return — the refund's identity, its booking, the resulting
/// status (<c>succeeded</c>/<c>failed</c>) and when it was stamped settled. Reconciliation of a BNPL/manual
/// refund's async customer cash-back.</summary>
public record RefundSettlementResult(
    long RefundId,
    long BookingId,
    string Status,
    DateTime? CompletedAt);

/// <summary>What <c>CreateRefundCommand</c> returns — the created refund's identity, channel, terminal-ish
/// status, decomposed legs and (BNPL) ETA, and whether it opened a clawback. Money is a digit string.</summary>
public record CreateRefundResult(
    long RefundId,
    long BookingId,
    string Status,
    string RefundChannel,
    string Amount,
    string PlatformFeeRefundedIrr,
    string NursePayoutRefundedIrr,
    DateOnly? ExpectedCustomerRefundEta,
    long? ClawbackId);
