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

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// EF Mig 38 G-O3 (S37) — Đề xuất aggregate root.
// Cookie-cutter mirror PurchaseEvaluationConfiguration pattern.
public class ProposalConfiguration : IEntityTypeConfiguration<Proposal>
{
    public void Configure(EntityTypeBuilder<Proposal> e)
    {
        e.ToTable("Proposals");

        e.Property(x => x.MaDeXuat).HasMaxLength(50);     // "DX/2026/001"
        e.Property(x => x.Title).HasMaxLength(300).IsRequired();
        e.Property(x => x.Description).HasMaxLength(5000);
        e.Property(x => x.AmountEstimate).HasColumnType("decimal(18,2)");
        e.Property(x => x.Status).HasConversion<int>();
        e.Property(x => x.RejectedFromStatus).HasConversion<int>();

        // MaDeXuat optional UNIQUE (gen sau Submit lần đầu)
        e.HasIndex(x => x.MaDeXuat).IsUnique().HasFilter("[MaDeXuat] IS NOT NULL");

        // Index Status + Drafter cho list filter/inbox
        e.HasIndex(x => x.Status);
        e.HasIndex(x => x.DrafterUserId);
        e.HasIndex(x => x.DepartmentId);
        e.HasIndex(x => x.ApprovalWorkflowId);
    }
}
