using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Monitoring.Infrastructure.Data.Migrations
{
    /// <inheritdoc />
    public partial class AddTypeToReportsAndLockedEventCodes : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "Type",
                table: "Reports",
                type: "integer",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "LockedEventCodes",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    AssetId = table.Column<Guid>(type: "uuid", nullable: false),
                    EventCodeId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_LockedEventCodes", x => x.Id);
                    table.ForeignKey(
                        name: "FK_LockedEventCodes_Assets_AssetId",
                        column: x => x.AssetId,
                        principalTable: "Assets",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_LockedEventCodes_EventCodes_EventCodeId",
                        column: x => x.EventCodeId,
                        principalTable: "EventCodes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_LockedEventCodes_AssetId_EventCodeId",
                table: "LockedEventCodes",
                columns: new[] { "AssetId", "EventCodeId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_LockedEventCodes_EventCodeId",
                table: "LockedEventCodes",
                column: "EventCodeId");
        }

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

            migrationBuilder.DropColumn(
                name: "Type",
                table: "Reports");
        }
    }
}
