using Baya.Domain.Entities.Invoices;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Baya.Infrastructure.Persistence.Configuration.InvoicesConfig;

/// <summary>
/// The single-row counter behind the sequential <c>invoice_number</c>. Seeded with one row (id 1, next = 1) so
/// <c>EnsureCreated</c> (tests) and the migration both start the sequence. The id is fixed (never generated) —
/// there is exactly one counter. Portable across SQL Server and SQLite (no provider-specific DB sequence).
/// </summary>
internal sealed class InvoiceNumberSequenceConfig : IEntityTypeConfiguration<InvoiceNumberSequence>
{
    public void Configure(EntityTypeBuilder<InvoiceNumberSequence> builder)
    {
        builder.ToTable("InvoiceNumberSequences", "payments");

        builder.HasKey(s => s.Id);
        builder.Property(s => s.Id).ValueGeneratedNever();

        builder.HasData(new InvoiceNumberSequence { Id = 1, NextValue = 1 });
    }
}
