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

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// EF Mig 41 P11-A (Phase 11) — Ý kiến cấp duyệt V2 dynamic cho VehicleBooking.
// Cookie-cutter mirror ProposalLevelOpinionConfiguration (Mig 38).
public class VehicleBookingLevelOpinionConfiguration : IEntityTypeConfiguration<VehicleBookingLevelOpinion>
{
    public void Configure(EntityTypeBuilder<VehicleBookingLevelOpinion> e)
    {
        e.ToTable("VehicleBookingLevelOpinions");

        e.Property(x => x.Comment).HasMaxLength(2000);
        e.Property(x => x.SignedByFullName).HasMaxLength(200).IsRequired();

        e.HasOne(x => x.VehicleBooking)
            .WithMany(p => p.LevelOpinions)
            .HasForeignKey(x => x.VehicleBookingId)
            .OnDelete(DeleteBehavior.Cascade);

        e.HasOne(x => x.Level)
            .WithMany()
            .HasForeignKey(x => x.ApprovalWorkflowLevelId)
            .OnDelete(DeleteBehavior.Restrict);

        e.HasIndex(x => new { x.VehicleBookingId, x.ApprovalWorkflowLevelId }).IsUnique();
        e.HasIndex(x => x.ApprovalWorkflowLevelId);
    }
}
