// <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 VigilCare.WardGateway.Migrations
{
    [DbContext(typeof(GatewayDbContext))]
    [Migration("20260623073142_InitialGatewaySchema")]
    partial class InitialGatewaySchema
    {
        /// <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("BufferedSyncItem", 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")
                        .IsRequired()
                        .HasMaxLength(200)
                        .HasColumnType("character varying(200)")
                        .HasColumnName("idempotency_key");

                    b.Property<string>("ItemType")
                        .IsRequired()
                        .HasMaxLength(32)
                        .HasColumnType("character varying(32)")
                        .HasColumnName("item_type");

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

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

                    b.Property<bool>("Synced")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("boolean")
                        .HasDefaultValue(false)
                        .HasColumnName("synced");

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

                    b.HasKey("Id");

                    b.HasIndex("CreatedAt")
                        .HasFilter("NOT synced");

                    b.HasIndex("IdempotencyKey")
                        .IsUnique()
                        .HasFilter("NOT synced");

                    b.ToTable("buffered_sync_items", null, t =>
                        {
                            t.HasCheckConstraint("chk_buffered_sync_items_item_type", "item_type IN ('OBSERVATION', 'ALERT', 'ACK', 'RESOLVE')");
                        });
                });

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

                    b.Property<bool>("InitialSyncCompleted")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("boolean")
                        .HasDefaultValue(false)
                        .HasColumnName("initial_sync_completed");

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

                    b.HasKey("Id");

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

            modelBuilder.Entity("LocalClinicalAlert", 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<Guid>("ClientAlertId")
                        .HasColumnType("uuid")
                        .HasColumnName("client_alert_id");

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

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

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

                    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("ClientAlertId")
                        .IsUnique();

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

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

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

                    b.HasIndex("EncounterId", "AlertType", "ObservationCode")
                        .HasFilter("status IN ('OPEN', 'ESCALATED')");

                    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', 'CRITICAL_SYSTOLIC_BP', 'CRITICAL_DIASTOLIC_BP', 'CRITICAL_LACTATE_MMOL_L', 'CRITICAL_AVPU', 'CRITICAL_GLUCOSE_MG_DL', 'CRITICAL_PAO2_MMHG', 'CRITICAL_PLATELET_K_UL', 'CRITICAL_BILIRUBIN_MG_DL', 'CRITICAL_CREATININE_MG_DL', 'WARNING_HEART_RATE', 'WARNING_TEMP_C', 'WARNING_POTASSIUM_MEQ_L', 'WARNING_SPO2', 'WARNING_RESP_RATE', 'WARNING_WBC_K_UL', 'WARNING_SYSTOLIC_BP', 'WARNING_DIASTOLIC_BP', 'WARNING_LACTATE_MMOL_L', 'WARNING_GLUCOSE_MG_DL', 'WARNING_PAO2_MMHG', 'WARNING_PLATELET_K_UL', 'WARNING_BILIRUBIN_MG_DL', 'WARNING_CREATININE_MG_DL', 'NEWS2_WARNING', 'NEWS2_EMERGENCY', 'RAPID_DETERIORATION', 'QSOFA_WARNING', 'QSOFA_SCREEN', 'GCS_CRITICAL', 'GCS_WARNING', 'SOFA_SEPSIS', 'SOFA_WARNING')");

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

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

            modelBuilder.Entity("LocalObservation", 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("ReplicaAlertThreshold", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    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<int?>("SuppressionWindowMinutes")
                        .HasColumnType("integer")
                        .HasColumnName("suppression_window_minutes");

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

                    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("ReplicaEncounter", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

                    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<string>("Department")
                        .IsRequired()
                        .HasMaxLength(100)
                        .HasColumnType("character varying(100)")
                        .HasColumnName("department");

                    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.Property<DateTimeOffset>("SyncedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("synced_at");

                    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("ReplicaPatient", b =>
                {
                    b.Property<Guid>("Id")
                        .ValueGeneratedOnAdd()
                        .HasColumnType("uuid")
                        .HasColumnName("id")
                        .HasDefaultValueSql("gen_random_uuid()");

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

                    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<DateTimeOffset>("SyncedAt")
                        .HasColumnType("timestamp with time zone")
                        .HasColumnName("synced_at");

                    b.HasKey("Id");

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

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

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

                    b.Property<Guid?>("BatchId")
                        .HasColumnType("uuid")
                        .HasColumnName("batch_id");

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

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

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

                    b.HasKey("Id");

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

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

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

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

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

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

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

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

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

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