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

namespace SolutionErp.Infrastructure.Persistence.Configurations;

public class ProjectConfiguration : IEntityTypeConfiguration<Project>
{
    public void Configure(EntityTypeBuilder<Project> b)
    {
        b.ToTable("Projects");
        b.HasKey(x => x.Id);

        b.Property(x => x.Code).HasMaxLength(50).IsRequired();
        b.Property(x => x.Name).HasMaxLength(200).IsRequired();
        b.Property(x => x.BudgetTotal).HasPrecision(18, 2);
        b.Property(x => x.Note).HasMaxLength(1000);
        b.Property(x => x.Investor).HasMaxLength(250);   // Chủ đầu tư
        b.Property(x => x.Location).HasMaxLength(500);    // Địa điểm
        b.Property(x => x.Package).HasMaxLength(300);     // Gói thầu

        b.HasIndex(x => x.Code).IsUnique().HasFilter("[IsDeleted] = 0");   // Mig 47 (gotcha #57 EXT) — soft-deleted slot reusable, khớp HasQueryFilter !IsDeleted app-check

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