using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace RobotNet.MapManager.Data.Migrations
{
    /// <inheritdoc />
    public partial class AddMapdb : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Maps",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", nullable: false),
                    Description = table.Column<string>(type: "ntext", nullable: true),
                    VersionId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    OriginX = table.Column<double>(type: "float", nullable: false),
                    OriginY = table.Column<double>(type: "float", nullable: false),
                    Resolution = table.Column<double>(type: "float", nullable: false),
                    ViewX = table.Column<double>(type: "float", nullable: false),
                    ViewY = table.Column<double>(type: "float", nullable: false),
                    ViewWidth = table.Column<double>(type: "float", nullable: false),
                    ViewHeight = table.Column<double>(type: "float", nullable: false),
                    ImageWidth = table.Column<double>(type: "float", nullable: false),
                    ImageHeight = table.Column<double>(type: "float", nullable: false),
                    NodeCount = table.Column<long>(type: "BigInt", nullable: false),
                    Active = table.Column<bool>(type: "bit", nullable: false),
                    VDA5050 = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    NodeNameAutoGenerate = table.Column<bool>(type: "bit", nullable: false),
                    NodeNameTemplateDefault = table.Column<string>(type: "nvarchar(64)", nullable: true),
                    NodeAllowedDeviationXyDefault = table.Column<double>(type: "float", nullable: false),
                    NodeAllowedDeviationThetaDefault = table.Column<double>(type: "float", nullable: false),
                    EdgeMinLengthDefault = table.Column<double>(type: "float", nullable: false),
                    EdgeStraightMaxSpeedDefault = table.Column<double>(type: "float", nullable: false),
                    EdgeCurveMaxSpeedDefault = table.Column<double>(type: "float", nullable: false),
                    EdgeMaxHeightDefault = table.Column<double>(type: "float", nullable: false),
                    EdgeMinHeightDefault = table.Column<double>(type: "float", nullable: false),
                    EdgeMaxRoataionSpeedDefault = table.Column<double>(type: "float", nullable: false),
                    EdgeDirectionAllowedDefault = table.Column<byte>(type: "tinyint", nullable: false),
                    EdgeRotationAllowedDefault = table.Column<bool>(type: "bit", nullable: false),
                    EdgeAllowedDeviationXyDefault = table.Column<double>(type: "float", nullable: false),
                    EdgeAllowedDeviationThetaDefault = table.Column<double>(type: "float", nullable: false),
                    ZoneMinSquareDefault = table.Column<double>(type: "float", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Maps", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Actions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MapId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", nullable: true),
                    Content = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Actions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Actions_Maps_MapId",
                        column: x => x.MapId,
                        principalTable: "Maps",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "ElementModels",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MapId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", nullable: true),
                    Width = table.Column<double>(type: "float", nullable: false),
                    Height = table.Column<double>(type: "float", nullable: false),
                    Image1Width = table.Column<int>(type: "int", nullable: false),
                    Image1Height = table.Column<int>(type: "int", nullable: false),
                    Image2Width = table.Column<int>(type: "int", nullable: false),
                    Image2Height = table.Column<int>(type: "int", nullable: false),
                    Content = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ElementModels", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ElementModels_Maps_MapId",
                        column: x => x.MapId,
                        principalTable: "Maps",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Nodes",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MapId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", nullable: true),
                    X = table.Column<double>(type: "float", nullable: false),
                    Y = table.Column<double>(type: "float", nullable: false),
                    Theta = table.Column<double>(type: "float", nullable: false),
                    AllowedDeviationXy = table.Column<double>(type: "float", nullable: false),
                    AllowedDeviationTheta = table.Column<double>(type: "float", nullable: false),
                    Actions = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Nodes", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Nodes_Maps_MapId",
                        column: x => x.MapId,
                        principalTable: "Maps",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Zones",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MapId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false),
                    X1 = table.Column<double>(type: "float", nullable: false),
                    Y1 = table.Column<double>(type: "float", nullable: false),
                    X2 = table.Column<double>(type: "float", nullable: false),
                    Y2 = table.Column<double>(type: "float", nullable: false),
                    X3 = table.Column<double>(type: "float", nullable: false),
                    Y3 = table.Column<double>(type: "float", nullable: false),
                    X4 = table.Column<double>(type: "float", nullable: false),
                    Y4 = table.Column<double>(type: "float", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Zones", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Zones_Maps_MapId",
                        column: x => x.MapId,
                        principalTable: "Maps",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Edges",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MapId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    StartNodeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    EndNodeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ControlPoint1X = table.Column<double>(type: "float", nullable: false),
                    ControlPoint1Y = table.Column<double>(type: "float", nullable: false),
                    ControlPoint2X = table.Column<double>(type: "float", nullable: false),
                    ControlPoint2Y = table.Column<double>(type: "float", nullable: false),
                    TrajectoryDegree = table.Column<byte>(type: "tinyint", nullable: false),
                    MaxHeight = table.Column<double>(type: "float", nullable: false),
                    MinHeight = table.Column<double>(type: "float", nullable: false),
                    DirectionAllowed = table.Column<byte>(type: "tinyint", nullable: false),
                    RotationAllowed = table.Column<bool>(type: "bit", nullable: false),
                    MaxRotationSpeed = table.Column<double>(type: "float", nullable: false),
                    MaxSpeed = table.Column<double>(type: "float", nullable: false),
                    AllowedDeviationXy = table.Column<double>(type: "float", nullable: false),
                    AllowedDeviationTheta = table.Column<double>(type: "float", nullable: false),
                    Actions = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Edges", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Edges_Maps_MapId",
                        column: x => x.MapId,
                        principalTable: "Maps",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Edges_Nodes_EndNodeId",
                        column: x => x.EndNodeId,
                        principalTable: "Nodes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Edges_Nodes_StartNodeId",
                        column: x => x.StartNodeId,
                        principalTable: "Nodes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateTable(
                name: "Elements",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MapId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ModelId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    NodeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(64)", nullable: true),
                    IsOpen = table.Column<bool>(type: "bit", nullable: false),
                    OffsetX = table.Column<double>(type: "float", nullable: false),
                    OffsetY = table.Column<double>(type: "float", nullable: false),
                    Content = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Elements", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Elements_ElementModels_ModelId",
                        column: x => x.ModelId,
                        principalTable: "ElementModels",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Elements_Maps_MapId",
                        column: x => x.MapId,
                        principalTable: "Maps",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_Elements_Nodes_NodeId",
                        column: x => x.NodeId,
                        principalTable: "Nodes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Action_MapId_Name",
                table: "Actions",
                columns: new[] { "MapId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Edge_MapId",
                table: "Edges",
                column: "MapId");

            migrationBuilder.CreateIndex(
                name: "IX_Edges_EndNodeId",
                table: "Edges",
                column: "EndNodeId");

            migrationBuilder.CreateIndex(
                name: "IX_Edges_StartNodeId",
                table: "Edges",
                column: "StartNodeId");

            migrationBuilder.CreateIndex(
                name: "IX_ElementModel_MapId_Name",
                table: "ElementModels",
                columns: new[] { "MapId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Element_MapId_ModelId",
                table: "Elements",
                columns: new[] { "MapId", "ModelId" });

            migrationBuilder.CreateIndex(
                name: "IX_Elements_ModelId",
                table: "Elements",
                column: "ModelId");

            migrationBuilder.CreateIndex(
                name: "IX_Elements_NodeId",
                table: "Elements",
                column: "NodeId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Node_MapId_Name",
                table: "Nodes",
                columns: new[] { "MapId", "Name" });

            migrationBuilder.CreateIndex(
                name: "IX_Zone_MapId",
                table: "Zones",
                column: "MapId");
        }

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

            migrationBuilder.DropTable(
                name: "Edges");

            migrationBuilder.DropTable(
                name: "Elements");

            migrationBuilder.DropTable(
                name: "Zones");

            migrationBuilder.DropTable(
                name: "ElementModels");

            migrationBuilder.DropTable(
                name: "Nodes");

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