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

public class MedicationAdministrationConfiguration : IEntityTypeConfiguration<MedicationAdministration>
{
    public void Configure(EntityTypeBuilder<MedicationAdministration> builder)
    {
        builder.ToTable("medication_administrations");
        builder.HasKey(m => m.Id);
        builder.Property(m => m.Id).HasColumnName("id").HasDefaultValueSql("gen_random_uuid()");
        builder.Property(m => m.EncounterId).HasColumnName("encounter_id").IsRequired();
        builder.Property(m => m.DrugName).HasColumnName("drug_name").HasMaxLength(200).IsRequired();
        builder.Property(m => m.Dose).HasColumnName("dose").HasPrecision(10, 4).IsRequired();
        builder.Property(m => m.DoseUnit).HasColumnName("dose_unit").HasMaxLength(20).IsRequired();
        builder.Property(m => m.Route).HasColumnName("route").HasMaxLength(50).IsRequired();
        builder.Property(m => m.AdministeredAt).HasColumnName("administered_at").IsRequired();
        builder.Property(m => m.AdministeredBy).HasColumnName("administered_by").HasMaxLength(100).IsRequired();

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

        builder.HasIndex(m => new { m.EncounterId, m.AdministeredAt });
        builder.HasIndex(m => new { m.EncounterId, m.DrugName });
    }
}