using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Monitoring.Infrastructure.Data.Migrations;

/// <inheritdoc />
public partial class RemoveAssetFromZone : Migration
{
	/// <inheritdoc />
	protected override void Up(MigrationBuilder migrationBuilder)
	{
		_ = migrationBuilder.DropForeignKey(
			name: "FK_Zones_Areas_AreaId",
			table: "Zones");

		_ = migrationBuilder.DropForeignKey(
			name: "FK_Zones_Assets_AssetId",
			table: "Zones");

		_ = migrationBuilder.DropIndex(
			name: "IX_Zones_AreaId",
			table: "Zones");

		_ = migrationBuilder.DropIndex(
			name: "IX_Zones_AssetId_Index",
			table: "Zones");

		_ = migrationBuilder.DropColumn(
			name: "AssetId",
			table: "Zones");

		_ = migrationBuilder.AlterColumn<Guid>(
			name: "AreaId",
			table: "Zones",
			type: "uuid",
			nullable: false,
			defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
			oldClrType: typeof(Guid),
			oldType: "uuid",
			oldNullable: true);

		_ = migrationBuilder.CreateIndex(
			name: "IX_Zones_AreaId_Index",
			table: "Zones",
			columns: new[] { "AreaId", "Index" },
			unique: true);

		_ = migrationBuilder.AddForeignKey(
			name: "FK_Zones_Areas_AreaId",
			table: "Zones",
			column: "AreaId",
			principalTable: "Areas",
			principalColumn: "Id",
			onDelete: ReferentialAction.Cascade);
	}

	/// <inheritdoc />
	protected override void Down(MigrationBuilder migrationBuilder)
	{
		_ = migrationBuilder.DropForeignKey(
			name: "FK_Zones_Areas_AreaId",
			table: "Zones");

		_ = migrationBuilder.DropIndex(
			name: "IX_Zones_AreaId_Index",
			table: "Zones");

		_ = migrationBuilder.AlterColumn<Guid>(
			name: "AreaId",
			table: "Zones",
			type: "uuid",
			nullable: true,
			oldClrType: typeof(Guid),
			oldType: "uuid");

		_ = migrationBuilder.AddColumn<Guid>(
			name: "AssetId",
			table: "Zones",
			type: "uuid",
			nullable: false,
			defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

		_ = migrationBuilder.CreateIndex(
			name: "IX_Zones_AreaId",
			table: "Zones",
			column: "AreaId");

		_ = migrationBuilder.CreateIndex(
			name: "IX_Zones_AssetId_Index",
			table: "Zones",
			columns: new[] { "AssetId", "Index" },
			unique: true);

		_ = migrationBuilder.AddForeignKey(
			name: "FK_Zones_Areas_AreaId",
			table: "Zones",
			column: "AreaId",
			principalTable: "Areas",
			principalColumn: "Id",
			onDelete: ReferentialAction.SetNull);

		_ = migrationBuilder.AddForeignKey(
			name: "FK_Zones_Assets_AssetId",
			table: "Zones",
			column: "AssetId",
			principalTable: "Assets",
			principalColumn: "Id",
			onDelete: ReferentialAction.Cascade);
	}
}
