using ERPCore.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace ERPCore.Infra.Persistence.Configurations;

public sealed class ReasonCodeConfiguration : IEntityTypeConfiguration<ReasonCode>
{
    public void Configure(EntityTypeBuilder<ReasonCode> builder)
    {
        builder.ToTable("reason_codes");
        builder.HasKey(r => r.ReasonCodeId);

        builder.Property(r => r.Code).IsRequired().HasMaxLength(20);
        builder.Property(r => r.Description).IsRequired().HasMaxLength(200);
        builder.Property(r => r.Context).HasConversion<string>().HasMaxLength(20).IsRequired();

        builder.HasIndex(r => new { r.Context, r.Code }).IsUnique();
    }
}
