using Books.Api.Domain.Invoices;
using EventFlow.Aggregates;

namespace Books.Api.Domain.Invoices.Events;

/// <summary>
/// Raised when a new invoice or credit note draft is created.
/// At this point, the invoice/credit note number is assigned (Momsloven §52).
/// </summary>
public class InvoiceCreatedEvent(
    string companyId,
    string fiscalYearId,
    string customerId,
    string customerName,
    string customerNumber,
    string invoiceNumber,
    DateOnly invoiceDate,
    DateOnly dueDate,
    int paymentTermsDays,
    string currency,
    string? vatCode,
    string? notes,
    string? reference,
    string createdBy,
    InvoiceType type = InvoiceType.Invoice,
    string? originalInvoiceId = null,
    string? originalInvoiceNumber = null,
    string? creditReason = null) : AggregateEvent<InvoiceAggregate, InvoiceId>
{
    public string CompanyId { get; } = companyId;
    public string FiscalYearId { get; } = fiscalYearId;
    public string CustomerId { get; } = customerId;
    public string CustomerName { get; } = customerName;
    public string CustomerNumber { get; } = customerNumber;
    public string InvoiceNumber { get; } = invoiceNumber;
    public DateOnly InvoiceDate { get; } = invoiceDate;
    public DateOnly DueDate { get; } = dueDate;
    public int PaymentTermsDays { get; } = paymentTermsDays;
    public string Currency { get; } = currency;
    public string? VatCode { get; } = vatCode;
    public string? Notes { get; } = notes;
    public string? Reference { get; } = reference;
    public string CreatedBy { get; } = createdBy;

    /// <summary>
    /// Type of document: Invoice or CreditNote.
    /// </summary>
    public InvoiceType Type { get; } = type;

    /// <summary>
    /// For credit notes: Reference to the original invoice being credited.
    /// </summary>
    public string? OriginalInvoiceId { get; } = originalInvoiceId;

    /// <summary>
    /// For credit notes: The invoice number of the original invoice.
    /// </summary>
    public string? OriginalInvoiceNumber { get; } = originalInvoiceNumber;

    /// <summary>
    /// For credit notes: Reason for issuing the credit note.
    /// </summary>
    public string? CreditReason { get; } = creditReason;
}
