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

public class GcsScoreConfiguration : IEntityTypeConfiguration<GcsScore>
{
    public void Configure(EntityTypeBuilder<GcsScore> builder)
    {
        builder.ToTable("gcs_scores", t =>
        {
            t.HasCheckConstraint("chk_gcs_scores_classification",
                "classification IN ('MILD', 'MODERATE', 'SEVERE')");
        });
        builder.HasKey(g => g.Id);
        builder.Property(g => g.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
        builder.Property(g => g.EncounterId).HasColumnName("encounter_id").IsRequired();
        builder.Property(g => g.PatientId).HasColumnName("patient_id").IsRequired();
        builder.Property(g => g.EyeScore).HasColumnName("eye_score").IsRequired();
        builder.Property(g => g.VerbalScore).HasColumnName("verbal_score").IsRequired();
        builder.Property(g => g.MotorScore).HasColumnName("motor_score").IsRequired();
        builder.Property(g => g.TotalScore).HasColumnName("total_score").IsRequired();
        builder.Property(g => g.Classification).HasColumnName("classification").HasMaxLength(16).IsRequired();
        builder.Property(g => g.CalculatedAt).HasColumnName("calculated_at").IsRequired();
        builder.Property(g => g.CreatedAt).HasColumnName("created_at").IsRequired();

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

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