using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class TblApplications : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_V1_ApplicationsInHost_V1_Applications_ApplicationId",
                table: "V1_ApplicationsInHost");

            migrationBuilder.DropForeignKey(
                name: "FK_V1_Jobs_V1_Applications_ApplicationId",
                table: "V1_Jobs");

            migrationBuilder.DropTable(
                name: "V1_Applications");

            migrationBuilder.DropTable(
                name: "V1_ApplicationTypes");

            migrationBuilder.CreateTable(
                name: "ApplicationTypes",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
                    Name = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: true),
                    ApplicationTypeId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ApplicationTypes", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ApplicationTypes_ApplicationTypes_ApplicationTypeId",
                        column: x => x.ApplicationTypeId,
                        principalTable: "ApplicationTypes",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "Applications",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
                    Name = table.Column<string>(type: "text", nullable: false),
                    ApplicationTypeId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Applications", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Applications_ApplicationTypes_ApplicationTypeId",
                        column: x => x.ApplicationTypeId,
                        principalTable: "ApplicationTypes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.InsertData(
                table: "ApplicationTypes",
                columns: new[] { "Id", "ApplicationTypeId", "DateCreated", "DateModified", "Description", "Name" },
                values: new object[,]
                {
                    { new Guid("32c28386-6f13-4f7b-8508-be165b7fabdb"), null, new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "Поле СП xml АИХ ИТ", "APP" },
                    { new Guid("7848a96c-cdee-48c1-a786-de9cb889723a"), null, new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "Поле ОС xml АИХ ИТ", "OS" },
                    { new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"), null, new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "Поле СУБД xml АИХ ИТ", "DB" }
                });

            migrationBuilder.CreateIndex(
                name: "IX_Applications_ApplicationTypeId",
                table: "Applications",
                column: "ApplicationTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_ApplicationTypes_ApplicationTypeId",
                table: "ApplicationTypes",
                column: "ApplicationTypeId");

            migrationBuilder.AddForeignKey(
                name: "FK_V1_ApplicationsInHost_Applications_ApplicationId",
                table: "V1_ApplicationsInHost",
                column: "ApplicationId",
                principalTable: "Applications",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_V1_Jobs_Applications_ApplicationId",
                table: "V1_Jobs",
                column: "ApplicationId",
                principalTable: "Applications",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

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

            migrationBuilder.DropForeignKey(
                name: "FK_V1_Jobs_Applications_ApplicationId",
                table: "V1_Jobs");

            migrationBuilder.DropTable(
                name: "Applications");

            migrationBuilder.DropTable(
                name: "ApplicationTypes");

            migrationBuilder.CreateTable(
                name: "V1_ApplicationTypes",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
                    Description = table.Column<string>(type: "text", nullable: true),
                    Name = table.Column<string>(type: "text", nullable: false),
                    V1_ApplicationTypeId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_V1_ApplicationTypes", x => x.Id);
                    table.ForeignKey(
                        name: "FK_V1_ApplicationTypes_V1_ApplicationTypes_V1_ApplicationTypeId",
                        column: x => x.V1_ApplicationTypeId,
                        principalTable: "V1_ApplicationTypes",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "V1_Applications",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ApplicationTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
                    Name = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_V1_Applications", x => x.Id);
                    table.ForeignKey(
                        name: "FK_V1_Applications_V1_ApplicationTypes_ApplicationTypeId",
                        column: x => x.ApplicationTypeId,
                        principalTable: "V1_ApplicationTypes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.InsertData(
                table: "V1_ApplicationTypes",
                columns: new[] { "Id", "DateCreated", "DateModified", "Description", "Name", "V1_ApplicationTypeId" },
                values: new object[,]
                {
                    { new Guid("32c28386-6f13-4f7b-8508-be165b7fabdb"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "Поле СП xml АИХ ИТ", "APP", null },
                    { new Guid("7848a96c-cdee-48c1-a786-de9cb889723a"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "Поле ОС xml АИХ ИТ", "OS", null },
                    { new Guid("aae2636f-b93a-42dc-873e-0764a90a0a40"), new DateTimeOffset(new DateTime(2023, 5, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)), null, "Поле СУБД xml АИХ ИТ", "DB", null }
                });

            migrationBuilder.CreateIndex(
                name: "IX_V1_Applications_ApplicationTypeId",
                table: "V1_Applications",
                column: "ApplicationTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_V1_ApplicationTypes_V1_ApplicationTypeId",
                table: "V1_ApplicationTypes",
                column: "V1_ApplicationTypeId");

            migrationBuilder.AddForeignKey(
                name: "FK_V1_ApplicationsInHost_V1_Applications_ApplicationId",
                table: "V1_ApplicationsInHost",
                column: "ApplicationId",
                principalTable: "V1_Applications",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_V1_Jobs_V1_Applications_ApplicationId",
                table: "V1_Jobs",
                column: "ApplicationId",
                principalTable: "V1_Applications",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
