using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

public class AlertQualityMetricConfiguration : IEntityTypeConfiguration<AlertQualityMetric>
{
    public void Configure(EntityTypeBuilder<AlertQualityMetric> builder)
    {
        builder.ToTable("alert_quality_metrics");
        builder.HasKey(m => m.Id);
        builder.Property(m => m.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
        builder.Property(m => m.AlertType).HasColumnName("alert_type").HasMaxLength(50).IsRequired()
            .HasConversion(v => v.ToDbString(), v => AlertTypeExtensions.FromDbString(v));
        builder.Property(m => m.WindowStart).HasColumnName("window_start").IsRequired();
        builder.Property(m => m.WindowEnd).HasColumnName("window_end").IsRequired();
        builder.Property(m => m.TotalAlerts).HasColumnName("total_alerts").IsRequired();
        builder.Property(m => m.AcknowledgedCount).HasColumnName("acknowledged_count").IsRequired();
        builder.Property(m => m.ResolvedCount).HasColumnName("resolved_count").IsRequired();
        builder.Property(m => m.EscalatedCount).HasColumnName("escalated_count").IsRequired();
        builder.Property(m => m.FeedbackUsefulCount).HasColumnName("feedback_useful_count").IsRequired();
        builder.Property(m => m.FeedbackFalsePositiveCount).HasColumnName("feedback_false_positive_count").IsRequired();
        builder.Property(m => m.FeedbackWouldActCount).HasColumnName("feedback_would_act_count").IsRequired();
        builder.Property(m => m.FeedbackCount).HasColumnName("feedback_count").IsRequired();
        builder.Property(m => m.AcknowledgementRate).HasColumnName("acknowledgement_rate").IsRequired();
        builder.Property(m => m.FalsePositiveRate).HasColumnName("false_positive_rate").IsRequired();
        builder.Property(m => m.UsefulRate).HasColumnName("useful_rate").IsRequired();
        builder.Property(m => m.WouldActRate).HasColumnName("would_act_rate").IsRequired();
        builder.Property(m => m.AvgSecondsToAcknowledge).HasColumnName("avg_seconds_to_acknowledge").IsRequired();
        builder.Property(m => m.AvgSecondsToResolution).HasColumnName("avg_seconds_to_resolution").IsRequired();
        builder.Property(m => m.ComputedAt).HasColumnName("computed_at").HasDefaultValueSql("NOW()");

        builder.HasIndex(m => new { m.AlertType, m.WindowStart, m.WindowEnd }).IsUnique();
        builder.HasIndex(m => m.WindowStart);
    }
}