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

namespace Baya.Infrastructure.Persistence.Configuration.VerificationConfig;

internal sealed class VerificationStepTypeConfig : IEntityTypeConfiguration<VerificationStepType>
{
    public void Configure(EntityTypeBuilder<VerificationStepType> builder)
    {
        builder.ToTable("VerificationStepTypes", "verif");

        builder.Property(t => t.Code).HasMaxLength(50).IsRequired();
        builder.Property(t => t.DisplayName).HasMaxLength(150).IsRequired();
        builder.Property(t => t.Description).HasMaxLength(500);
        builder.Property(t => t.AutomationProvider).HasMaxLength(50);
        builder.Property(t => t.IsRequired).HasDefaultValue(false);
        builder.Property(t => t.IsAutomated).HasDefaultValue(false);
        builder.Property(t => t.SortOrder).HasDefaultValue(0);
        builder.Property(t => t.IsActive).HasDefaultValue(true);

        // Stable machine code — the data-driven pipeline's identity; one nurse-step joins on it.
        builder.HasIndex(t => t.Code).IsUnique();

        // Ordered admin/nurse browse of the active catalog.
        builder.HasIndex(t => new { t.IsActive, t.SortOrder });

        // The six step-types are seeded via HasData; the resulting InsertData is captured in a dedicated
        // seed migration (SeedVerificationStepTypes), kept separate from the table-creation migration.
        builder.HasData(VerificationStepTypeSeed.StepTypes());
    }
}
