using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
{
    /// <inheritdoc />
    public partial class AddEquipmentImportBatch : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "EquipmentImportBatch",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ClusterId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    CreatedBy = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    CreatedAtUtc = table.Column<DateTime>(type: "datetime2(3)", nullable: false),
                    RowsStaged = table.Column<int>(type: "int", nullable: false),
                    RowsAccepted = table.Column<int>(type: "int", nullable: false),
                    RowsRejected = table.Column<int>(type: "int", nullable: false),
                    FinalisedAtUtc = table.Column<DateTime>(type: "datetime2(3)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EquipmentImportBatch", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "EquipmentImportRow",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    BatchId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    LineNumberInFile = table.Column<int>(type: "int", nullable: false),
                    IsAccepted = table.Column<bool>(type: "bit", nullable: false),
                    RejectReason = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    ZTag = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    MachineCode = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    SAPID = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    EquipmentId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    EquipmentUuid = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    Name = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    UnsAreaName = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    UnsLineName = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    Manufacturer = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                    Model = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                    SerialNumber = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
                    HardwareRevision = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    SoftwareRevision = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    YearOfConstruction = table.Column<string>(type: "nvarchar(8)", maxLength: 8, nullable: true),
                    AssetLocation = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    ManufacturerUri = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
                    DeviceManualUri = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EquipmentImportRow", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EquipmentImportRow_EquipmentImportBatch_BatchId",
                        column: x => x.BatchId,
                        principalTable: "EquipmentImportBatch",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_EquipmentImportBatch_Creator_Finalised",
                table: "EquipmentImportBatch",
                columns: new[] { "CreatedBy", "FinalisedAtUtc" });

            migrationBuilder.CreateIndex(
                name: "IX_EquipmentImportRow_Batch",
                table: "EquipmentImportRow",
                column: "BatchId");
        }

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

            migrationBuilder.DropTable(
                name: "EquipmentImportBatch");
        }
    }
}
