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

public class News2ScoreConfiguration : IEntityTypeConfiguration<News2Score>
{
    public void Configure(EntityTypeBuilder<News2Score> builder)
    {
        builder.ToTable("news2_scores", t =>
        {
            t.HasCheckConstraint("chk_news2_scores_risk_level",
                "risk_level IN ('LOW', 'LOW_MEDIUM', 'MEDIUM', 'HIGH')");
        });
        builder.HasKey(n => n.Id);
        builder.Property(n => n.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
        builder.Property(n => n.EncounterId).HasColumnName("encounter_id").IsRequired();
        builder.Property(n => n.PatientId).HasColumnName("patient_id").IsRequired();
        builder.Property(n => n.TotalScore).HasColumnName("total_score").IsRequired();
        builder.Property(n => n.RiskLevel).HasColumnName("risk_level").HasMaxLength(20).IsRequired();
        builder.Property(n => n.RespRateScore).HasColumnName("resp_rate_score").IsRequired();
        builder.Property(n => n.Spo2Score).HasColumnName("spo2_score").IsRequired();
        builder.Property(n => n.SystolicBpScore).HasColumnName("systolic_bp_score").IsRequired();
        builder.Property(n => n.HeartRateScore).HasColumnName("heart_rate_score").IsRequired();
        builder.Property(n => n.ConsciousnessScore).HasColumnName("consciousness_score").IsRequired();
        builder.Property(n => n.TemperatureScore).HasColumnName("temperature_score").IsRequired();
        builder.Property(n => n.SupplementalO2Score).HasColumnName("supplemental_o2_score").IsRequired();
        builder.Property(n => n.HasSingleParamThree).HasColumnName("has_single_param_three").IsRequired();
        builder.Property(n => n.CalculatedAt).HasColumnName("calculated_at").IsRequired();

        builder.HasOne(n => n.Encounter)
            .WithMany()
            .HasForeignKey(n => n.EncounterId)
            .OnDelete(DeleteBehavior.Restrict);

        builder.HasIndex(n => new { n.EncounterId, n.CalculatedAt });
        builder.HasIndex(n => new { n.PatientId, n.CalculatedAt });
    }
}