// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace VigilCareClinicalAPI.Migrations
{
    [DbContext(typeof(AppDbContext))]
    [Migration("20260618073333_AddOrderResultSummary")]
    partial class AddOrderResultSummary
    {
        /// <inheritdoc />
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
        {
#pragma warning disable 612, 618
            modelBuilder
                .HasAnnotation("ProductVersion", "8.0.4")
                .HasAnnotation("Relational:MaxIdentifierLength", 63);

            NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);

            modelBuilder.Entity("AlertThreshold", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<decimal?>("CriticalHigh")
                        .HasColumnType("decimal(10,3)")
                        .HasColumnName("critical_high");

                    b.Property<decimal?>("CriticalLow")
                        .HasColumnType("decimal(10,3)")
                        .HasColumnName("critical_low");

                    b.Property<string>("DisplayName")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("display_name");

                    b.Property<string>("ObservationCode")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("observation_code");

                    b.Property<string>("Unit")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("unit");

                    b.Property<decimal?>("WarningHigh")
                        .HasColumnType("decimal(10,3)")
                        .HasColumnName("warning_high");

                    b.Property<decimal?>("WarningLow")
                        .HasColumnType("decimal(10,3)")
                        .HasColumnName("warning_low");

                    b.HasKey("Id");

                    b.HasIndex("ObservationCode")
                        .IsUnique();

                    b.ToTable("alert_thresholds", (string)null);
                });

            modelBuilder.Entity("ClinicalAlert", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset?>("AcknowledgedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("acknowledged_at");

                    b.Property<string>("AcknowledgedBy")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("acknowledged_by");

                    b.Property<string>("AlertType")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("alert_type");

                    b.Property<string>("Details")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("details");

                    b.Property<Guid>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<Guid?>("ObservationId")
                        .HasColumnType("uuid")
                        .HasColumnName("observation_id");

                    b.Property<Guid>("PatientId")
                        .HasColumnType("uuid")
                        .HasColumnName("patient_id");

                    b.Property<DateTimeOffset?>("ResolvedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("resolved_at");

                    b.Property<string>("Severity")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("severity");

                    b.Property<string>("Status")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("status")
                        .HasDefaultValueSql("'OPEN'");

                    b.Property<DateTimeOffset>("TriggeredAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("triggered_at")
                        .HasDefaultValueSql("NOW()");

                    b.HasKey("Id");

                    b.HasIndex("EncounterId", "TriggeredAt");

                    b.HasIndex("PatientId", "TriggeredAt");

                    b.HasIndex("Severity", "TriggeredAt")
                        .HasFilter("status = 'OPEN'");

                    b.ToTable("clinical_alerts", null, t =>
                        {
                            t.HasCheckConstraint("chk_clinical_alerts_alert_type", "alert_type IN ('SEPSIS_WARNING', 'CRITICAL_HEART_RATE', 'CRITICAL_TEMP_C', 'CRITICAL_POTASSIUM_MEQ_L', 'CRITICAL_SPO2', 'CRITICAL_RESP_RATE', 'CRITICAL_WBC_K_UL')");

                            t.HasCheckConstraint("chk_clinical_alerts_severity", "severity IN ('WARNING', 'CRITICAL')");

                            t.HasCheckConstraint("chk_clinical_alerts_status", "status IN ('OPEN', 'ACKNOWLEDGED', 'RESOLVED', 'ESCALATED')");
                        });
                });

            modelBuilder.Entity("Encounter", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("AdmissionReason")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("admission_reason");

                    b.Property<DateTimeOffset>("AdmittedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("admitted_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("AttendingPhysician")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("attending_physician");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("Department")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("department");

                    b.Property<string>("DischargeDiagnosis")
                        .HasMaxLength(500)
                        .HasColumnType("character varying(500)")
                        .HasColumnName("discharge_diagnosis");

                    b.Property<DateTimeOffset?>("DischargedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("discharged_at");

                    b.Property<string>("EncounterType")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("encounter_type");

                    b.Property<Guid>("PatientId")
                        .HasColumnType("uuid")
                        .HasColumnName("patient_id");

                    b.Property<string>("RoomBed")
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("room_bed");

                    b.Property<string>("Status")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("status")
                        .HasDefaultValueSql("'SCHEDULED'");

                    b.HasKey("Id");

                    b.HasIndex("PatientId", "AdmittedAt");

                    b.HasIndex("Status", "AdmittedAt")
                        .HasFilter("status = 'ACTIVE'");

                    b.ToTable("encounters", null, t =>
                        {
                            t.HasCheckConstraint("chk_encounters_department", "department IN ('ICU', 'GENERAL_MEDICINE', 'EMERGENCY', 'CARDIOLOGY', 'SURGERY', 'PEDIATRICS')");

                            t.HasCheckConstraint("chk_encounters_encounter_type", "encounter_type IN ('INPATIENT', 'OUTPATIENT', 'EMERGENCY')");

                            t.HasCheckConstraint("chk_encounters_status", "status IN ('SCHEDULED', 'ACTIVE', 'DISCHARGED', 'CANCELLED')");
                        });
                });

            modelBuilder.Entity("Observation", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<Guid>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<string>("IdempotencyKey")
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("idempotency_key");

                    b.Property<string>("ObservationCode")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("observation_code");

                    b.Property<DateTimeOffset>("RecordedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("recorded_at");

                    b.Property<string>("Source")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("source")
                        .HasDefaultValueSql("'MANUAL'");

                    b.Property<string>("Unit")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("unit");

                    b.Property<decimal>("Value")
                        .HasColumnType("decimal(10,3)")
                        .HasColumnName("value");

                    b.HasKey("Id");

                    b.HasIndex("IdempotencyKey")
                        .IsUnique()
                        .HasFilter("idempotency_key IS NOT NULL");

                    b.HasIndex("EncounterId", "ObservationCode", "RecordedAt");

                    b.ToTable("observations", null, t =>
                        {
                            t.HasCheckConstraint("chk_observations_source", "source IN ('MANUAL', 'DEVICE', 'LAB')");
                        });
                });

            modelBuilder.Entity("Order", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Description")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("description");

                    b.Property<Guid>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<string>("OrderType")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("order_type");

                    b.Property<DateTimeOffset>("OrderedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("ordered_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("OrderedBy")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("ordered_by");

                    b.Property<string>("ResultSummary")
                        .HasColumnType("text")
                        .HasColumnName("result_summary");

                    b.Property<DateTimeOffset?>("ResultedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("resulted_at");

                    b.Property<string>("Status")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("status")
                        .HasDefaultValueSql("'PENDING'");

                    b.HasKey("Id");

                    b.HasIndex("EncounterId", "OrderedAt");

                    b.HasIndex("Status", "OrderedAt")
                        .HasFilter("status IN ('PENDING', 'IN_PROGRESS')");

                    b.ToTable("orders", null, t =>
                        {
                            t.HasCheckConstraint("chk_orders_order_type", "order_type IN ('LAB', 'IMAGING', 'MEDICATION', 'PROCEDURE')");

                            t.HasCheckConstraint("chk_orders_status", "status IN ('PENDING', 'IN_PROGRESS', 'RESULTED', 'CANCELLED')");
                        });
                });

            modelBuilder.Entity("OutboxEvent", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("PartitionKey")
                        .HasMaxLength(36)
                        .HasColumnType("character varying(36)")
                        .HasColumnName("partition_key");

                    b.Property<string>("Payload")
                        .IsRequired()
                        .HasColumnType("jsonb")
                        .HasColumnName("payload");

                    b.Property<DateTimeOffset?>("ProcessedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("processed_at");

                    b.Property<string>("Topic")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("topic");

                    b.HasKey("Id");

                    b.HasIndex("CreatedAt")
                        .HasFilter("processed_at IS NULL");

                    b.ToTable("outbox_events", (string)null);
                });

            modelBuilder.Entity("Patient", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("Allergies")
                        .HasColumnType("text")
                        .HasColumnName("allergies");

                    b.Property<string>("BloodType")
                        .HasMaxLength(5)
                        .HasColumnType("character varying(5)")
                        .HasColumnName("blood_type");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<DateOnly>("DateOfBirth")
                        .HasColumnType("date")
                        .HasColumnName("date_of_birth");

                    b.Property<string>("EmergencyContactName")
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("emergency_contact_name");

                    b.Property<string>("EmergencyContactPhone")
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("emergency_contact_phone");

                    b.Property<string>("FirstName")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("first_name");

                    b.Property<string>("Gender")
                        .IsRequired()
                        .HasMaxLength(10)
                        .HasColumnType("character varying(10)")
                        .HasColumnName("gender");

                    b.Property<string>("LastName")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("last_name");

                    b.Property<string>("Mrn")
                        .IsRequired()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasColumnName("mrn");

                    b.Property<string>("Status")
                        .IsRequired()
                        .ValueGeneratedOnAdd()
                        .HasMaxLength(20)
                        .HasColumnType("character varying(20)")
                        .HasDefaultValue("active")
                        .HasColumnName("status");

                    b.HasKey("Id");

                    b.HasIndex("Mrn")
                        .IsUnique();

                    b.ToTable("patients", (string)null);
                });

            modelBuilder.Entity("ReconciliationAlert", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    b.Property<string>("CheckType")
                        .IsRequired()
                        .HasMaxLength(50)
                        .HasColumnType("character varying(50)")
                        .HasColumnName("check_type");

                    b.Property<DateTimeOffset>("CreatedAt")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("created_at")
                        .HasDefaultValueSql("NOW()");

                    b.Property<string>("Details")
                        .IsRequired()
                        .HasColumnType("text")
                        .HasColumnName("details");

                    b.Property<Guid?>("EncounterId")
                        .HasColumnType("uuid")
                        .HasColumnName("encounter_id");

                    b.Property<Guid?>("PatientId")
                        .HasColumnType("uuid")
                        .HasColumnName("patient_id");

                    b.Property<DateTimeOffset?>("ResolvedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("resolved_at");

                    b.HasKey("Id");

                    b.HasIndex("EncounterId");

                    b.HasIndex("PatientId");

                    b.HasIndex("CheckType", "EncounterId")
                        .HasFilter("resolved_at IS NULL");

                    b.ToTable("reconciliation_alerts", null, t =>
                        {
                            t.HasCheckConstraint("chk_reconciliation_alerts_check_type", "check_type IN ('UNACKNOWLEDGED_CRITICAL_ALERT', 'PENDING_ORDER_NO_RESULT', 'ACTIVE_INPATIENT_NO_OBSERVATION')");
                        });
                });

            modelBuilder.Entity("ClinicalAlert", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany("Alerts")
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");
                });

            modelBuilder.Entity("Encounter", b =>
                {
                    b.HasOne("Patient", "Patient")
                        .WithMany("Encounters")
                        .HasForeignKey("PatientId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Patient");
                });

            modelBuilder.Entity("Observation", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany("Observations")
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");
                });

            modelBuilder.Entity("Order", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany("Orders")
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.Restrict)
                        .IsRequired();

                    b.Navigation("Encounter");
                });

            modelBuilder.Entity("ReconciliationAlert", b =>
                {
                    b.HasOne("Encounter", "Encounter")
                        .WithMany()
                        .HasForeignKey("EncounterId")
                        .OnDelete(DeleteBehavior.SetNull);

                    b.HasOne("Patient", "Patient")
                        .WithMany()
                        .HasForeignKey("PatientId")
                        .OnDelete(DeleteBehavior.SetNull);

                    b.Navigation("Encounter");

                    b.Navigation("Patient");
                });

            modelBuilder.Entity("Encounter", b =>
                {
                    b.Navigation("Alerts");

                    b.Navigation("Observations");

                    b.Navigation("Orders");
                });

            modelBuilder.Entity("Patient", b =>
                {
                    b.Navigation("Encounters");
                });
#pragma warning restore 612, 618
        }
    }
}
