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

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// EF Mig 34 — Quá trình công tác (satellite). FK Cascade EmployeeProfile.
public class EmployeeWorkHistoryConfiguration : IEntityTypeConfiguration<EmployeeWorkHistory>
{
    public void Configure(EntityTypeBuilder<EmployeeWorkHistory> e)
    {
        e.ToTable("EmployeeWorkHistories");

        e.Property(x => x.CompanyName).HasMaxLength(200).IsRequired();
        e.Property(x => x.CompanyAddress).HasMaxLength(500);
        e.Property(x => x.Industry).HasMaxLength(200);

        e.Property(x => x.JobTitle).HasMaxLength(200);
        e.Property(x => x.JobDescription).HasMaxLength(2000);
        e.Property(x => x.ResignReason).HasMaxLength(500);

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

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