using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SolutionErp.Domain.Hrm;

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// EF Mig 44 P11-C (S51) — Danh mục tài xế. Catalog standalone, no FK.
// UNIQUE Code filtered WHERE IsDeleted=0 (gotcha #57 — soft-deleted slot reusable,
// khớp app-level !IsDeleted check + pattern HolidayConfiguration/Catalogs/Contract/PE).
public class DriverConfiguration : IEntityTypeConfiguration<Driver>
{
    public void Configure(EntityTypeBuilder<Driver> e)
    {
        e.ToTable("Drivers");

        e.Property(x => x.Code).HasMaxLength(50).IsRequired();
        e.Property(x => x.Name).HasMaxLength(200).IsRequired();
        e.Property(x => x.PhoneNumber).HasMaxLength(20).IsRequired();
        e.Property(x => x.LicenseNumber).HasMaxLength(50).IsRequired();
        e.Property(x => x.LicenseClass).HasMaxLength(20).IsRequired();
        e.Property(x => x.Description).HasMaxLength(500);

        e.HasIndex(x => x.Code).IsUnique().HasFilter("[IsDeleted] = 0");
    }
}
