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

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// EF Mig 34 — Quan hệ gia đình (satellite). FK Cascade EmployeeProfile.
public class EmployeeFamilyRelationConfiguration : IEntityTypeConfiguration<EmployeeFamilyRelation>
{
    public void Configure(EntityTypeBuilder<EmployeeFamilyRelation> e)
    {
        e.ToTable("EmployeeFamilyRelations");

        e.Property(x => x.FullName).HasMaxLength(200).IsRequired();
        e.Property(x => x.Occupation).HasMaxLength(200);
        e.Property(x => x.CurrentAddress).HasMaxLength(500);
        e.Property(x => x.Phone).HasMaxLength(20);

        e.HasOne(x => x.EmployeeProfile)
            .WithMany(p => p.FamilyRelations)
            .HasForeignKey(x => x.EmployeeProfileId)
            .OnDelete(DeleteBehavior.Cascade);

        e.HasIndex(x => x.EmployeeProfileId);
    }
}
