using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HospitalManagementSystem.Migrations
{
    /// <inheritdoc />
    public partial class patientdocument_entitydocument : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "LabReportUrl",
                table: "PatientRecords");

            migrationBuilder.DropColumn(
                name: "MedicationHistoryUrl",
                table: "PatientRecords");

            migrationBuilder.DropColumn(
                name: "MedicationUrl",
                table: "PatientRecords");

            migrationBuilder.AddColumn<Guid>(
                name: "LabReportUrlId",
                table: "PatientRecords",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "MedicationHistoryUrlId",
                table: "PatientRecords",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "MedicationUrlId",
                table: "PatientRecords",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "ImagesId",
                table: "Patient",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "EntityDocuments",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    OriginalFileName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    GeneratedFileName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FileSize = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FilePath = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    FileType = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    TagName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    UploadDate = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EntityDocuments", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PatientDocuments",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    PatientsId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    EntityDocumentsId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TagName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PatientDocuments", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PatientDocuments_EntityDocuments_EntityDocumentsId",
                        column: x => x.EntityDocumentsId,
                        principalTable: "EntityDocuments",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_PatientDocuments_Patient_PatientsId",
                        column: x => x.PatientsId,
                        principalTable: "Patient",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_PatientRecords_LabReportUrlId",
                table: "PatientRecords",
                column: "LabReportUrlId");

            migrationBuilder.CreateIndex(
                name: "IX_PatientRecords_MedicationHistoryUrlId",
                table: "PatientRecords",
                column: "MedicationHistoryUrlId");

            migrationBuilder.CreateIndex(
                name: "IX_PatientRecords_MedicationUrlId",
                table: "PatientRecords",
                column: "MedicationUrlId");

            migrationBuilder.CreateIndex(
                name: "IX_Patient_ImagesId",
                table: "Patient",
                column: "ImagesId");

            migrationBuilder.CreateIndex(
                name: "IX_PatientDocuments_EntityDocumentsId",
                table: "PatientDocuments",
                column: "EntityDocumentsId");

            migrationBuilder.CreateIndex(
                name: "IX_PatientDocuments_PatientsId",
                table: "PatientDocuments",
                column: "PatientsId");

            migrationBuilder.AddForeignKey(
                name: "FK_Patient_EntityDocuments_ImagesId",
                table: "Patient",
                column: "ImagesId",
                principalTable: "EntityDocuments",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_PatientRecords_EntityDocuments_LabReportUrlId",
                table: "PatientRecords",
                column: "LabReportUrlId",
                principalTable: "EntityDocuments",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_PatientRecords_EntityDocuments_MedicationHistoryUrlId",
                table: "PatientRecords",
                column: "MedicationHistoryUrlId",
                principalTable: "EntityDocuments",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_PatientRecords_EntityDocuments_MedicationUrlId",
                table: "PatientRecords",
                column: "MedicationUrlId",
                principalTable: "EntityDocuments",
                principalColumn: "Id");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Patient_EntityDocuments_ImagesId",
                table: "Patient");

            migrationBuilder.DropForeignKey(
                name: "FK_PatientRecords_EntityDocuments_LabReportUrlId",
                table: "PatientRecords");

            migrationBuilder.DropForeignKey(
                name: "FK_PatientRecords_EntityDocuments_MedicationHistoryUrlId",
                table: "PatientRecords");

            migrationBuilder.DropForeignKey(
                name: "FK_PatientRecords_EntityDocuments_MedicationUrlId",
                table: "PatientRecords");

            migrationBuilder.DropTable(
                name: "PatientDocuments");

            migrationBuilder.DropTable(
                name: "EntityDocuments");

            migrationBuilder.DropIndex(
                name: "IX_PatientRecords_LabReportUrlId",
                table: "PatientRecords");

            migrationBuilder.DropIndex(
                name: "IX_PatientRecords_MedicationHistoryUrlId",
                table: "PatientRecords");

            migrationBuilder.DropIndex(
                name: "IX_PatientRecords_MedicationUrlId",
                table: "PatientRecords");

            migrationBuilder.DropIndex(
                name: "IX_Patient_ImagesId",
                table: "Patient");

            migrationBuilder.DropColumn(
                name: "LabReportUrlId",
                table: "PatientRecords");

            migrationBuilder.DropColumn(
                name: "MedicationHistoryUrlId",
                table: "PatientRecords");

            migrationBuilder.DropColumn(
                name: "MedicationUrlId",
                table: "PatientRecords");

            migrationBuilder.DropColumn(
                name: "ImagesId",
                table: "Patient");

            migrationBuilder.AddColumn<string>(
                name: "LabReportUrl",
                table: "PatientRecords",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "MedicationHistoryUrl",
                table: "PatientRecords",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "MedicationUrl",
                table: "PatientRecords",
                type: "nvarchar(max)",
                nullable: true);
        }
    }
}
