using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SolutionErp.Domain.Master.Catalogs;

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// [K1 — S164, Mig 70] EF config cho danh mục Hợp đồng SOL-CCM-SP-002 (86 dòng).
// File RIÊNG (không nhét vào CatalogsConfiguration.cs) — mirror khuôn PE/KHKK
// 1-entity-1-file cho entity mới. Pattern: Code unique FILTERED [IsDeleted]=0
// (gotcha #57 — soft-delete phải filter) + query filter soft-delete + index
// ApprovalGroup cho picker K2 lọc theo nhóm phiếu.
public class ContractCatalogEntryConfiguration : IEntityTypeConfiguration<ContractCatalogEntry>
{
    public void Configure(EntityTypeBuilder<ContractCatalogEntry> b)
    {
        b.ToTable("ContractCatalogEntries");
        b.HasKey(x => x.Id);
        b.Property(x => x.Code).HasMaxLength(20).IsRequired();
        b.Property(x => x.TenVi).HasMaxLength(500).IsRequired();
        b.Property(x => x.TenEn).HasMaxLength(500);
        b.Property(x => x.GroupCode).HasMaxLength(10).IsRequired();
        b.Property(x => x.SignerRole).HasMaxLength(100).IsRequired();
        b.Property(x => x.InitialsChain).HasMaxLength(300);
        b.Property(x => x.NduqNote).HasMaxLength(500);
        b.Property(x => x.IsActive).HasDefaultValue(true);
        b.Property(x => x.SortOrder).HasDefaultValue(0);
        b.HasIndex(x => x.Code).IsUnique().HasFilter("[IsDeleted] = 0");
        b.HasIndex(x => x.ApprovalGroup);
        b.HasQueryFilter(x => !x.IsDeleted);
    }
}
