using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Integrations.Data.Migrations
{
    /// <inheritdoc />
    public partial class SplitSettingsToTables : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "Parameters",
                table: "Modules");

            migrationBuilder.CreateTable(
                name: "AdemcoSettings",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Port = table.Column<int>(type: "integer", nullable: false),
                    ModuleId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AdemcoSettings", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AdemcoSettings_Modules_ModuleId",
                        column: x => x.ModuleId,
                        principalTable: "Modules",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "GeoRitmSettings",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Port = table.Column<int>(type: "integer", nullable: false),
                    Url = table.Column<string>(type: "text", nullable: false),
                    ModuleId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_GeoRitmSettings", x => x.Id);
                    table.ForeignKey(
                        name: "FK_GeoRitmSettings_Modules_ModuleId",
                        column: x => x.ModuleId,
                        principalTable: "Modules",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AdemcoSettings_ModuleId",
                table: "AdemcoSettings",
                column: "ModuleId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_GeoRitmSettings_ModuleId",
                table: "GeoRitmSettings",
                column: "ModuleId",
                unique: true);
        }

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

            migrationBuilder.DropTable(
                name: "GeoRitmSettings");

            migrationBuilder.AddColumn<string>(
                name: "Parameters",
                table: "Modules",
                type: "jsonb",
                nullable: false,
                defaultValue: "");
        }
    }
}
