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

namespace ERPCore.Infra.Persistence.Configurations;

public sealed class HrDocumentTypeConfiguration : IEntityTypeConfiguration<HrDocumentType>
{
    public void Configure(EntityTypeBuilder<HrDocumentType> builder)
    {
        builder.ToTable("hr_document_types");
        builder.HasKey(t => t.HrDocumentTypeId);

        builder.Property(t => t.Code).IsRequired().HasMaxLength(20);
        builder.HasIndex(t => t.Code).IsUnique();
        builder.Property(t => t.Name).IsRequired().HasMaxLength(200);
        builder.Property(t => t.Category).HasConversion<string>().HasMaxLength(20).IsRequired();

        builder.Property(t => t.Status)
            .HasConversion<string>().HasMaxLength(20).IsRequired()
            .HasDefaultValue(EntityStatus.Active);

        builder.Property(t => t.CreatedAt).IsRequired();
        builder.Property(t => t.RowVersion).IsRowVersion();

        builder.HasIndex(t => t.Status);
    }
}
