using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Monitoring.Infrastructure.Data.Migrations
{
    /// <inheritdoc />
    public partial class AddAssetStatuses : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "AssetStatuses",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    AssetId = table.Column<Guid>(type: "uuid", nullable: false),
                    IsOnline = table.Column<bool>(type: "boolean", nullable: false),
                    Timestamp = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    StatusChangeReason = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AssetStatuses", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AssetStatuses_Assets_AssetId",
                        column: x => x.AssetId,
                        principalTable: "Assets",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AssetStatuses_AssetId",
                table: "AssetStatuses",
                column: "AssetId");

            migrationBuilder.CreateIndex(
                name: "IX_AssetStatuses_AssetId_Timestamp",
                table: "AssetStatuses",
                columns: new[] { "AssetId", "Timestamp" });

            migrationBuilder.CreateIndex(
                name: "IX_AssetStatuses_Timestamp",
                table: "AssetStatuses",
                column: "Timestamp");
        }

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