using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace VigilCareClinicalAPI.Migrations
{
    /// <inheritdoc />
    public partial class AddQsofaEvaluations : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "qsofa_evaluations",
                columns: table => new
                {
                    id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
                    encounter_id = table.Column<Guid>(type: "uuid", nullable: false),
                    patient_id = table.Column<Guid>(type: "uuid", nullable: false),
                    active_criteria = table.Column<int>(type: "integer", nullable: false),
                    resp_rate = table.Column<decimal>(type: "numeric", nullable: true),
                    systolic_bp = table.Column<decimal>(type: "numeric", nullable: true),
                    avpu = table.Column<decimal>(type: "numeric", nullable: true),
                    screen_alert_fired = table.Column<bool>(type: "boolean", nullable: false),
                    evaluated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_qsofa_evaluations", x => x.id);
                    table.CheckConstraint("chk_qsofa_evaluations_active_criteria", "active_criteria >= 0 AND active_criteria <= 3");
                    table.ForeignKey(
                        name: "FK_qsofa_evaluations_encounters_encounter_id",
                        column: x => x.encounter_id,
                        principalTable: "encounters",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_qsofa_evaluations_encounter_id_evaluated_at",
                table: "qsofa_evaluations",
                columns: new[] { "encounter_id", "evaluated_at" });
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "qsofa_evaluations");
        }
    }
}
