using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Migrations
{
    /// <inheritdoc />
    public partial class AddPendingSecuredWriteTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "PendingSecuredWrites",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    SiteId = table.Column<string>(type: "varchar(128)", unicode: false, maxLength: 128, nullable: false),
                    ConnectionName = table.Column<string>(type: "varchar(128)", unicode: false, maxLength: 128, nullable: false),
                    TagPath = table.Column<string>(type: "varchar(512)", unicode: false, maxLength: 512, nullable: false),
                    ValueJson = table.Column<string>(type: "varchar(4000)", unicode: false, maxLength: 4000, nullable: false),
                    ValueType = table.Column<string>(type: "varchar(128)", unicode: false, maxLength: 128, nullable: false),
                    Status = table.Column<string>(type: "varchar(32)", unicode: false, maxLength: 32, nullable: false),
                    OperatorUser = table.Column<string>(type: "varchar(256)", unicode: false, maxLength: 256, nullable: false),
                    OperatorComment = table.Column<string>(type: "varchar(1024)", unicode: false, maxLength: 1024, nullable: true),
                    SubmittedAtUtc = table.Column<DateTime>(type: "datetime2", nullable: false),
                    VerifierUser = table.Column<string>(type: "varchar(256)", unicode: false, maxLength: 256, nullable: true),
                    VerifierComment = table.Column<string>(type: "varchar(1024)", unicode: false, maxLength: 1024, nullable: true),
                    DecidedAtUtc = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ExecutedAtUtc = table.Column<DateTime>(type: "datetime2", nullable: true),
                    ExecutionError = table.Column<string>(type: "varchar(2048)", unicode: false, maxLength: 2048, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PendingSecuredWrites", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_PendingSecuredWrites_Site",
                table: "PendingSecuredWrites",
                column: "SiteId");

            migrationBuilder.CreateIndex(
                name: "IX_PendingSecuredWrites_Status_Submitted",
                table: "PendingSecuredWrites",
                columns: new[] { "Status", "SubmittedAtUtc" });
        }

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