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

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// [W1 Mig 69 — S161] Danh mục căn cứ (b.8-9): mẫu vật liệu / shopdrawing + kết quả TVGS.
public class ContractSigningPlanDossierItemConfiguration
    : IEntityTypeConfiguration<ContractSigningPlanDossierItem>
{
    public void Configure(EntityTypeBuilder<ContractSigningPlanDossierItem> b)
    {
        b.ToTable("ContractSigningPlanDossierItems");
        b.HasKey(x => x.Id);

        b.Property(x => x.Kind).HasConversion<int>();
        b.Property(x => x.Status).HasConversion<int>();
        b.Property(x => x.Name).HasMaxLength(500).IsRequired();
        b.Property(x => x.TvgsName).HasMaxLength(200);
        b.Property(x => x.Note).HasMaxLength(1000);

        b.HasIndex(x => x.ContractSigningPlanId);
        b.HasIndex(x => x.SupplierId);

        b.HasOne(x => x.ContractSigningPlan)
            .WithMany(p => p.DossierItems)
            .HasForeignKey(x => x.ContractSigningPlanId)
            .OnDelete(DeleteBehavior.Cascade);

        b.HasQueryFilter(x => !x.IsDeleted);
    }
}
