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

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// EF Mig 34 — Quá trình học vấn (satellite). FK Cascade EmployeeProfile.
public class EmployeeEducationConfiguration : IEntityTypeConfiguration<EmployeeEducation>
{
    public void Configure(EntityTypeBuilder<EmployeeEducation> e)
    {
        e.ToTable("EmployeeEducations");

        e.Property(x => x.SchoolName).HasMaxLength(200).IsRequired();
        e.Property(x => x.Major).HasMaxLength(200);
        e.Property(x => x.Notes).HasMaxLength(500);

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

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