using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

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

            migrationBuilder.AddColumn<Guid>(
                name: "InnerStepId",
                table: "PurchaseEvaluationDepartmentApprovals",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "PurchaseEvaluationWorkflowStepInnerSteps",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    PurchaseEvaluationWorkflowStepId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    Order = table.Column<int>(type: "int", nullable: false),
                    DepartmentId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    PositionLevel = table.Column<int>(type: "int", nullable: false),
                    Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
                    SlaDays = table.Column<int>(type: "int", nullable: true),
                    IsRequired = table.Column<bool>(type: "bit", 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)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PurchaseEvaluationWorkflowStepInnerSteps", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PurchaseEvaluationWorkflowStepInnerSteps_Departments_DepartmentId",
                        column: x => x.DepartmentId,
                        principalTable: "Departments",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_PurchaseEvaluationWorkflowStepInnerSteps_PurchaseEvaluationWorkflowSteps_PurchaseEvaluationWorkflowStepId",
                        column: x => x.PurchaseEvaluationWorkflowStepId,
                        principalTable: "PurchaseEvaluationWorkflowSteps",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_PurchaseEvaluationDepartmentApprovals_InnerStepId",
                table: "PurchaseEvaluationDepartmentApprovals",
                column: "InnerStepId");

            migrationBuilder.CreateIndex(
                name: "IX_PurchaseEvaluationWorkflowStepInnerSteps_DepartmentId",
                table: "PurchaseEvaluationWorkflowStepInnerSteps",
                column: "DepartmentId");

            migrationBuilder.CreateIndex(
                name: "IX_PurchaseEvaluationWorkflowStepInnerSteps_PurchaseEvaluationWorkflowStepId_Order",
                table: "PurchaseEvaluationWorkflowStepInnerSteps",
                columns: new[] { "PurchaseEvaluationWorkflowStepId", "Order" });

            migrationBuilder.AddForeignKey(
                name: "FK_PurchaseEvaluationDepartmentApprovals_PurchaseEvaluationWorkflowStepInnerSteps_InnerStepId",
                table: "PurchaseEvaluationDepartmentApprovals",
                column: "InnerStepId",
                principalTable: "PurchaseEvaluationWorkflowStepInnerSteps",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_PurchaseEvaluationDepartmentApprovals_PurchaseEvaluationWorkflowStepInnerSteps_InnerStepId",
                table: "PurchaseEvaluationDepartmentApprovals");

            migrationBuilder.DropTable(
                name: "PurchaseEvaluationWorkflowStepInnerSteps");

            migrationBuilder.DropIndex(
                name: "IX_PurchaseEvaluationDepartmentApprovals_InnerStepId",
                table: "PurchaseEvaluationDepartmentApprovals");

            migrationBuilder.DropColumn(
                name: "PositionLevel",
                table: "Users");

            migrationBuilder.DropColumn(
                name: "InnerStepId",
                table: "PurchaseEvaluationDepartmentApprovals");
        }
    }
}
