using Baya.Domain.Entities.SupportAlerts;
using Baya.Domain.Entities.User;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Baya.Infrastructure.Persistence.Configuration.SupportAlertsConfig;

internal sealed class SupportAlertConfig : IEntityTypeConfiguration<SupportAlert>
{
    public void Configure(EntityTypeBuilder<SupportAlert> builder)
    {
        builder.ToTable("SupportAlerts", "ops");

        builder.Property(a => a.Type).HasMaxLength(40).IsRequired();
        builder.Property(a => a.Severity).HasMaxLength(20).IsRequired();
        builder.Property(a => a.Status).HasMaxLength(20).IsRequired();
        builder.Property(a => a.EntityType).HasMaxLength(100).IsRequired();
        builder.Property(a => a.EntityId).HasMaxLength(100).IsRequired();

        builder.HasIndex(a => a.Status);
        builder.HasIndex(a => a.Type);

        builder.HasOne<User>()
            .WithMany()
            .HasForeignKey(a => a.OwnerUserId)
            .IsRequired(false);

        // BookingId/ReviewId are declared columns only — the FK constraints are added by the phases that
        // create the bookings/reviews tables (b9/b14), keeping this baseline migration additive-safe.
    }
}
