using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class TblApplicationsInHost : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<Guid>(
                name: "V1_ApplicationId",
                table: "V1_ApplicationsInHost",
                type: "uuid",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "ApplicationsInHost",
                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),
                    ApplicationId = table.Column<Guid>(type: "uuid", nullable: false),
                    HostId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ApplicationsInHost", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ApplicationsInHost_Applications_ApplicationId",
                        column: x => x.ApplicationId,
                        principalTable: "Applications",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ApplicationsInHost_Hosts_HostId",
                        column: x => x.HostId,
                        principalTable: "Hosts",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            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),
                    Name = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: true),
                    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),
                    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_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.CreateIndex(
                name: "IX_V1_ApplicationsInHost_V1_ApplicationId",
                table: "V1_ApplicationsInHost",
                column: "V1_ApplicationId");

            migrationBuilder.CreateIndex(
                name: "IX_ApplicationsInHost_ApplicationId",
                table: "ApplicationsInHost",
                column: "ApplicationId");

            migrationBuilder.CreateIndex(
                name: "IX_ApplicationsInHost_HostId",
                table: "ApplicationsInHost",
                column: "HostId");

            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_V1_ApplicationId",
                table: "V1_ApplicationsInHost",
                column: "V1_ApplicationId",
                principalTable: "V1_Applications",
                principalColumn: "Id");
        }

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

            migrationBuilder.DropTable(
                name: "ApplicationsInHost");

            migrationBuilder.DropTable(
                name: "V1_Applications");

            migrationBuilder.DropTable(
                name: "V1_ApplicationTypes");

            migrationBuilder.DropIndex(
                name: "IX_V1_ApplicationsInHost_V1_ApplicationId",
                table: "V1_ApplicationsInHost");

            migrationBuilder.DropColumn(
                name: "V1_ApplicationId",
                table: "V1_ApplicationsInHost");
        }
    }
}
