using EventFlow.Aggregates;

namespace Books.Api.Domain.Invoices.Events;

/// <summary>
/// Raised when a credit note is applied to an invoice.
/// This reduces the credit note's remaining amount and potentially the target invoice's balance.
/// </summary>
public class InvoiceCreditAppliedEvent(
    string appliedToInvoiceId,
    string appliedToInvoiceNumber,
    decimal amount,
    DateOnly appliedDate,
    string appliedBy,
    string? ledgerTransactionId,
    decimal newAmountApplied,
    decimal newAmountRemaining,
    InvoiceStatus newStatus) : AggregateEvent<InvoiceAggregate, InvoiceId>
{
    /// <summary>
    /// The invoice this credit note is being applied to.
    /// </summary>
    public string AppliedToInvoiceId { get; } = appliedToInvoiceId;

    /// <summary>
    /// The invoice number of the target invoice.
    /// </summary>
    public string AppliedToInvoiceNumber { get; } = appliedToInvoiceNumber;

    /// <summary>
    /// The amount of credit being applied.
    /// </summary>
    public decimal Amount { get; } = amount;

    /// <summary>
    /// The date the credit was applied.
    /// </summary>
    public DateOnly AppliedDate { get; } = appliedDate;

    /// <summary>
    /// User who applied the credit.
    /// </summary>
    public string AppliedBy { get; } = appliedBy;

    /// <summary>
    /// Reference to the ledger transaction created for this application.
    /// </summary>
    public string? LedgerTransactionId { get; } = ledgerTransactionId;

    /// <summary>
    /// Total amount applied after this operation.
    /// </summary>
    public decimal NewAmountApplied { get; } = newAmountApplied;

    /// <summary>
    /// Remaining credit amount after this operation.
    /// </summary>
    public decimal NewAmountRemaining { get; } = newAmountRemaining;

    /// <summary>
    /// New status after applying the credit.
    /// </summary>
    public InvoiceStatus NewStatus { get; } = newStatus;
}
