using Microsoft.EntityFrameworkCore.Migrations;

using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace GeoRitmMover.Mover.Data.Migrations;

/// <inheritdoc />
public partial class AddedAreas : Migration
{
	/// <inheritdoc />
	protected override void Up(MigrationBuilder migrationBuilder)
	{
		_ = migrationBuilder.DropTable(
			name: "Counters");

		_ = migrationBuilder.DropTable(
			name: "object_groups");

		_ = migrationBuilder.AlterColumn<int>(
			name: "From",
			table: "Groups",
			type: "integer",
			nullable: false,
			oldClrType: typeof(long),
			oldType: "bigint");

		_ = migrationBuilder.AlterColumn<int>(
			name: "From",
			table: "Assets",
			type: "integer",
			nullable: false,
			oldClrType: typeof(long),
			oldType: "bigint");

		_ = migrationBuilder.CreateTable(
			name: "Areas",
			columns: table => new
			{
				Id = table.Column<Guid>(type: "uuid", nullable: false),
				From = table.Column<int>(type: "integer", nullable: false),
				To = table.Column<Guid>(type: "uuid", nullable: false)
			},
			constraints: table =>
			{
				_ = table.PrimaryKey("PK_Areas", x => x.Id);
			});

		_ = migrationBuilder.CreateIndex(
			name: "IX_Areas_From",
			table: "Areas",
			column: "From",
			unique: true);

		_ = migrationBuilder.CreateIndex(
			name: "IX_Areas_To",
			table: "Areas",
			column: "To",
			unique: true);
	}

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

		_ = migrationBuilder.AlterColumn<long>(
			name: "From",
			table: "Groups",
			type: "bigint",
			nullable: false,
			oldClrType: typeof(int),
			oldType: "integer");

		_ = migrationBuilder.AlterColumn<long>(
			name: "From",
			table: "Assets",
			type: "bigint",
			nullable: false,
			oldClrType: typeof(int),
			oldType: "integer");

		_ = migrationBuilder.CreateTable(
			name: "Counters",
			columns: table => new
			{
				Id = table.Column<Guid>(type: "uuid", nullable: false),
				Name = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false)
			},
			constraints: table =>
			{
				_ = table.PrimaryKey("PK_Counters", x => x.Id);
			});

		_ = migrationBuilder.CreateTable(
			name: "object_groups",
			columns: table => new
			{
				id = table.Column<int>(type: "integer", nullable: false)
					.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
				name = table.Column<string>(type: "text", nullable: false)
			},
			constraints: table =>
			{
				_ = table.PrimaryKey("PK_object_groups", x => x.id);
			});

		_ = migrationBuilder.CreateIndex(
			name: "IX_Counters_Name",
			table: "Counters",
			column: "Name",
			unique: true);
	}
}
