using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace SolutionErp.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class WireWorkflowAppsApprovalV2 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "RejectedFromStatus",
                table: "VehicleBookings",
                type: "int",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "RejectedFromStatus",
                table: "TravelRequests",
                type: "int",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "RejectedFromStatus",
                table: "OtRequests",
                type: "int",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "RejectedFromStatus",
                table: "LeaveRequests",
                type: "int",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "LeaveRequestLevelOpinions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    LeaveRequestId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ApprovalWorkflowLevelId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Comment = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SignedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    SignedByUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SignedByFullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_LeaveRequestLevelOpinions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_LeaveRequestLevelOpinions_ApprovalWorkflowLevels_ApprovalWorkflowLevelId",
                        column: x => x.ApprovalWorkflowLevelId,
                        principalTable: "ApprovalWorkflowLevels",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_LeaveRequestLevelOpinions_LeaveRequests_LeaveRequestId",
                        column: x => x.LeaveRequestId,
                        principalTable: "LeaveRequests",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "OtRequestLevelOpinions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    OtRequestId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ApprovalWorkflowLevelId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Comment = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SignedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    SignedByUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SignedByFullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OtRequestLevelOpinions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_OtRequestLevelOpinions_ApprovalWorkflowLevels_ApprovalWorkflowLevelId",
                        column: x => x.ApprovalWorkflowLevelId,
                        principalTable: "ApprovalWorkflowLevels",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_OtRequestLevelOpinions_OtRequests_OtRequestId",
                        column: x => x.OtRequestId,
                        principalTable: "OtRequests",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "TravelRequestLevelOpinions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TravelRequestId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ApprovalWorkflowLevelId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Comment = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SignedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    SignedByUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SignedByFullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TravelRequestLevelOpinions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TravelRequestLevelOpinions_ApprovalWorkflowLevels_ApprovalWorkflowLevelId",
                        column: x => x.ApprovalWorkflowLevelId,
                        principalTable: "ApprovalWorkflowLevels",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_TravelRequestLevelOpinions_TravelRequests_TravelRequestId",
                        column: x => x.TravelRequestId,
                        principalTable: "TravelRequests",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "VehicleBookingLevelOpinions",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    VehicleBookingId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ApprovalWorkflowLevelId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Comment = table.Column<string>(type: "nvarchar(2000)", maxLength: 2000, nullable: true),
                    SignedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    SignedByUserId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    SignedByFullName = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    UpdatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_VehicleBookingLevelOpinions", x => x.Id);
                    table.ForeignKey(
                        name: "FK_VehicleBookingLevelOpinions_ApprovalWorkflowLevels_ApprovalWorkflowLevelId",
                        column: x => x.ApprovalWorkflowLevelId,
                        principalTable: "ApprovalWorkflowLevels",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_VehicleBookingLevelOpinions_VehicleBookings_VehicleBookingId",
                        column: x => x.VehicleBookingId,
                        principalTable: "VehicleBookings",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "WorkflowAppCodeSequences",
                columns: table => new
                {
                    Prefix = table.Column<string>(type: "nvarchar(20)", maxLength: 20, nullable: false),
                    LastSeq = table.Column<int>(type: "int", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WorkflowAppCodeSequences", x => x.Prefix);
                });

            migrationBuilder.CreateIndex(
                name: "IX_LeaveRequestLevelOpinions_ApprovalWorkflowLevelId",
                table: "LeaveRequestLevelOpinions",
                column: "ApprovalWorkflowLevelId");

            migrationBuilder.CreateIndex(
                name: "IX_LeaveRequestLevelOpinions_LeaveRequestId_ApprovalWorkflowLevelId",
                table: "LeaveRequestLevelOpinions",
                columns: new[] { "LeaveRequestId", "ApprovalWorkflowLevelId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_OtRequestLevelOpinions_ApprovalWorkflowLevelId",
                table: "OtRequestLevelOpinions",
                column: "ApprovalWorkflowLevelId");

            migrationBuilder.CreateIndex(
                name: "IX_OtRequestLevelOpinions_OtRequestId_ApprovalWorkflowLevelId",
                table: "OtRequestLevelOpinions",
                columns: new[] { "OtRequestId", "ApprovalWorkflowLevelId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_TravelRequestLevelOpinions_ApprovalWorkflowLevelId",
                table: "TravelRequestLevelOpinions",
                column: "ApprovalWorkflowLevelId");

            migrationBuilder.CreateIndex(
                name: "IX_TravelRequestLevelOpinions_TravelRequestId_ApprovalWorkflowLevelId",
                table: "TravelRequestLevelOpinions",
                columns: new[] { "TravelRequestId", "ApprovalWorkflowLevelId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_VehicleBookingLevelOpinions_ApprovalWorkflowLevelId",
                table: "VehicleBookingLevelOpinions",
                column: "ApprovalWorkflowLevelId");

            migrationBuilder.CreateIndex(
                name: "IX_VehicleBookingLevelOpinions_VehicleBookingId_ApprovalWorkflowLevelId",
                table: "VehicleBookingLevelOpinions",
                columns: new[] { "VehicleBookingId", "ApprovalWorkflowLevelId" },
                unique: true);
        }

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

            migrationBuilder.DropTable(
                name: "OtRequestLevelOpinions");

            migrationBuilder.DropTable(
                name: "TravelRequestLevelOpinions");

            migrationBuilder.DropTable(
                name: "VehicleBookingLevelOpinions");

            migrationBuilder.DropTable(
                name: "WorkflowAppCodeSequences");

            migrationBuilder.DropColumn(
                name: "RejectedFromStatus",
                table: "VehicleBookings");

            migrationBuilder.DropColumn(
                name: "RejectedFromStatus",
                table: "TravelRequests");

            migrationBuilder.DropColumn(
                name: "RejectedFromStatus",
                table: "OtRequests");

            migrationBuilder.DropColumn(
                name: "RejectedFromStatus",
                table: "LeaveRequests");
        }
    }
}
