using Baya.Domain.Common;

namespace Baya.Domain.Entities.Invoices;

/// <summary>
/// The gap-free, concurrency-safe counter behind <c>invoices.invoice_number</c>. A single seeded row holds the
/// next value; issuing an invoice takes the money-path lock, reads and increments <see cref="NextValue"/>, and
/// commits the increment <b>in the same transaction</b> as the invoice insert — so a rollback rolls both back
/// and numbers stay sequential and unique. A dedicated counter row (not <c>MAX()+1</c>) keeps this correct under
/// concurrency and portable across SQL Server and the SQLite test provider (no provider-specific sequence).
/// </summary>
public class InvoiceNumberSequence : IEntity
{
    /// <summary>Fixed singleton key — there is exactly one counter row (id 1).</summary>
    public int Id { get; set; }

    /// <summary>The next number to hand out. Incremented under the invoice lock.</summary>
    public long NextValue { get; set; }
}
