using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Monitoring.Infrastructure.Data.Migrations
{
    /// <inheritdoc />
    public partial class AddCameraAndFireDept : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<bool>(
                name: "IsAccepted",
                table: "Alarms",
                type: "boolean",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "IsReal",
                table: "Alarms",
                type: "boolean",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "IsResolved",
                table: "Alarms",
                type: "boolean",
                nullable: false,
                defaultValue: false);

            migrationBuilder.CreateTable(
                name: "AlarmAcceptances",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    AlarmId = table.Column<Guid>(type: "uuid", nullable: false),
                    AcceptedById = table.Column<Guid>(type: "uuid", nullable: false),
                    AcceptedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    TransferredToId = table.Column<Guid>(type: "uuid", nullable: true),
                    TransferredAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AlarmAcceptances", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AlarmAcceptances_Alarms_AlarmId",
                        column: x => x.AlarmId,
                        principalTable: "Alarms",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_AlarmAcceptances_Users_AcceptedById",
                        column: x => x.AcceptedById,
                        principalTable: "Users",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_AlarmAcceptances_Users_TransferredToId",
                        column: x => x.TransferredToId,
                        principalTable: "Users",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "AlarmFireDepartmentDispatches",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    AlarmId = table.Column<Guid>(type: "uuid", nullable: false),
                    SenderId = table.Column<Guid>(type: "uuid", nullable: false),
                    SentAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    DepartmentId = table.Column<Guid>(type: "uuid", nullable: false),
                    DispatcherName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    Comment = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AlarmFireDepartmentDispatches", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AlarmFireDepartmentDispatches_Alarms_AlarmId",
                        column: x => x.AlarmId,
                        principalTable: "Alarms",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_AlarmFireDepartmentDispatches_Users_SenderId",
                        column: x => x.SenderId,
                        principalTable: "Users",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "AlarmResets",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    AlarmId = table.Column<Guid>(type: "uuid", nullable: false),
                    ResetById = table.Column<Guid>(type: "uuid", nullable: false),
                    ResetAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    Comment = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AlarmResets", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AlarmResets_Alarms_AlarmId",
                        column: x => x.AlarmId,
                        principalTable: "Alarms",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_AlarmResets_Users_ResetById",
                        column: x => x.ResetById,
                        principalTable: "Users",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "Calls",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    AlarmId = table.Column<Guid>(type: "uuid", nullable: false),
                    CallerId = table.Column<Guid>(type: "uuid", nullable: false),
                    StartedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    ResponsiblePersonId = table.Column<Guid>(type: "uuid", nullable: false),
                    IsConfirmedRealAlarm = table.Column<bool>(type: "boolean", nullable: false),
                    Commentary = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Calls", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Calls_Alarms_AlarmId",
                        column: x => x.AlarmId,
                        principalTable: "Alarms",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Calls_ResponsiblePersons_ResponsiblePersonId",
                        column: x => x.ResponsiblePersonId,
                        principalTable: "ResponsiblePersons",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_Calls_Users_CallerId",
                        column: x => x.CallerId,
                        principalTable: "Users",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "Cameras",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    Address = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    AssetId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Cameras", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Cameras_Assets_AssetId",
                        column: x => x.AssetId,
                        principalTable: "Assets",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "FireDepartments",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    Address = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FireDepartments", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "CameraViews",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    UserId = table.Column<Guid>(type: "uuid", nullable: false),
                    CameraId = table.Column<Guid>(type: "uuid", nullable: false),
                    AlarmId = table.Column<Guid>(type: "uuid", nullable: false),
                    DateTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    StartVideo = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    EndVideo = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CameraViews", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CameraViews_Alarms_AlarmId",
                        column: x => x.AlarmId,
                        principalTable: "Alarms",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_CameraViews_Cameras_CameraId",
                        column: x => x.CameraId,
                        principalTable: "Cameras",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_CameraViews_Users_UserId",
                        column: x => x.UserId,
                        principalTable: "Users",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "FireDepartmentAccesses",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    UserId = table.Column<Guid>(type: "uuid", nullable: false),
                    DepartmentId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FireDepartmentAccesses", x => x.Id);
                    table.ForeignKey(
                        name: "FK_FireDepartmentAccesses_FireDepartments_DepartmentId",
                        column: x => x.DepartmentId,
                        principalTable: "FireDepartments",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_FireDepartmentAccesses_Users_UserId",
                        column: x => x.UserId,
                        principalTable: "Users",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_AlarmAcceptances_AcceptedById",
                table: "AlarmAcceptances",
                column: "AcceptedById");

            migrationBuilder.CreateIndex(
                name: "IX_AlarmAcceptances_AlarmId",
                table: "AlarmAcceptances",
                column: "AlarmId");

            migrationBuilder.CreateIndex(
                name: "IX_AlarmAcceptances_TransferredToId",
                table: "AlarmAcceptances",
                column: "TransferredToId");

            migrationBuilder.CreateIndex(
                name: "IX_AlarmFireDepartmentDispatches_AlarmId",
                table: "AlarmFireDepartmentDispatches",
                column: "AlarmId");

            migrationBuilder.CreateIndex(
                name: "IX_AlarmFireDepartmentDispatches_SenderId",
                table: "AlarmFireDepartmentDispatches",
                column: "SenderId");

            migrationBuilder.CreateIndex(
                name: "IX_AlarmResets_AlarmId",
                table: "AlarmResets",
                column: "AlarmId");

            migrationBuilder.CreateIndex(
                name: "IX_AlarmResets_ResetById",
                table: "AlarmResets",
                column: "ResetById");

            migrationBuilder.CreateIndex(
                name: "IX_Calls_AlarmId",
                table: "Calls",
                column: "AlarmId");

            migrationBuilder.CreateIndex(
                name: "IX_Calls_CallerId",
                table: "Calls",
                column: "CallerId");

            migrationBuilder.CreateIndex(
                name: "IX_Calls_ResponsiblePersonId",
                table: "Calls",
                column: "ResponsiblePersonId");

            migrationBuilder.CreateIndex(
                name: "IX_Cameras_AssetId",
                table: "Cameras",
                column: "AssetId");

            migrationBuilder.CreateIndex(
                name: "IX_CameraViews_AlarmId",
                table: "CameraViews",
                column: "AlarmId");

            migrationBuilder.CreateIndex(
                name: "IX_CameraViews_CameraId_DateTime",
                table: "CameraViews",
                columns: new[] { "CameraId", "DateTime" });

            migrationBuilder.CreateIndex(
                name: "IX_CameraViews_UserId_DateTime",
                table: "CameraViews",
                columns: new[] { "UserId", "DateTime" });

            migrationBuilder.CreateIndex(
                name: "IX_FireDepartmentAccesses_DepartmentId",
                table: "FireDepartmentAccesses",
                column: "DepartmentId");

            migrationBuilder.CreateIndex(
                name: "IX_FireDepartmentAccesses_UserId_DepartmentId",
                table: "FireDepartmentAccesses",
                columns: new[] { "UserId", "DepartmentId" },
                unique: true);
        }

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

            migrationBuilder.DropTable(
                name: "AlarmFireDepartmentDispatches");

            migrationBuilder.DropTable(
                name: "AlarmResets");

            migrationBuilder.DropTable(
                name: "Calls");

            migrationBuilder.DropTable(
                name: "CameraViews");

            migrationBuilder.DropTable(
                name: "FireDepartmentAccesses");

            migrationBuilder.DropTable(
                name: "Cameras");

            migrationBuilder.DropTable(
                name: "FireDepartments");

            migrationBuilder.DropColumn(
                name: "IsAccepted",
                table: "Alarms");

            migrationBuilder.DropColumn(
                name: "IsReal",
                table: "Alarms");

            migrationBuilder.DropColumn(
                name: "IsResolved",
                table: "Alarms");
        }
    }
}
