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

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// EF Mig 34 — File scan attachment (satellite). FK Cascade EmployeeProfile.
// INDEX DocumentType cho filter "tất cả bằng cấp của NV X".
public class EmployeeDocumentConfiguration : IEntityTypeConfiguration<EmployeeDocument>
{
    public void Configure(EntityTypeBuilder<EmployeeDocument> e)
    {
        e.ToTable("EmployeeDocuments");

        e.Property(x => x.FileName).HasMaxLength(255).IsRequired();
        e.Property(x => x.FilePath).HasMaxLength(500).IsRequired();
        e.Property(x => x.ContentType).HasMaxLength(100).IsRequired();
        e.Property(x => x.Notes).HasMaxLength(500);

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

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