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

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// EF Mig 34 — Skill polymorphic Kind=Computer/Language/Other.
// FK Cascade EmployeeProfile. INDEX Kind cho filter "tất cả ngoại ngữ của NV X".
public class EmployeeSkillConfiguration : IEntityTypeConfiguration<EmployeeSkill>
{
    public void Configure(EntityTypeBuilder<EmployeeSkill> e)
    {
        e.ToTable("EmployeeSkills");

        e.Property(x => x.Name).HasMaxLength(200).IsRequired();
        e.Property(x => x.LanguageId).HasMaxLength(20);
        e.Property(x => x.Level).HasMaxLength(200);

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

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