using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Baya.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class RefinementPhase3TierB : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "TaskResultsJson",
                schema: "reviews",
                table: "PatientCareRecords",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "PatientCarePlans",
                schema: "usr",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    PatientId = table.Column<long>(type: "bigint", nullable: false),
                    MedicationsJson = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    RoutineJson = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    TasksJson = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    DeletedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
                    CreatedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
                    ModifiedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
                    CreatedById = table.Column<int>(type: "int", nullable: true),
                    ModifiedById = table.Column<int>(type: "int", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PatientCarePlans", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PatientCarePlans_Patients_PatientId",
                        column: x => x.PatientId,
                        principalSchema: "usr",
                        principalTable: "Patients",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "UX_PatientCarePlans_Patient",
                schema: "usr",
                table: "PatientCarePlans",
                column: "PatientId",
                unique: true,
                filter: "[DeletedAt] IS NULL");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "PatientCarePlans",
                schema: "usr");

            migrationBuilder.DropColumn(
                name: "TaskResultsJson",
                schema: "reviews",
                table: "PatientCareRecords");
        }
    }
}
