using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional

namespace Marco.Pms.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class Added_Apporved_By_In_TaskAllocation_Table : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<Guid>(
                name: "ApprovedById",
                table: "TaskAllocations",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<DateTime>(
                name: "ApprovedDate",
                table: "TaskAllocations",
                type: "datetime(6)",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "ParentTaskId",
                table: "TaskAllocations",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<Guid>(
                name: "ReportedById",
                table: "TaskAllocations",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<double>(
                name: "ReportedTask",
                table: "TaskAllocations",
                type: "double",
                nullable: false,
                defaultValue: 0.0);

            migrationBuilder.AddColumn<Guid>(
                name: "WorkStatusId",
                table: "TaskAllocations",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci");

            migrationBuilder.CreateTable(
                name: "WorkStatusMasters",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    Name = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Description = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IsSystem = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    TenantId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WorkStatusMasters", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WorkStatusMasters_Tenants_TenantId",
                        column: x => x.TenantId,
                        principalTable: "Tenants",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.InsertData(
                table: "WorkStatusMasters",
                columns: new[] { "Id", "Description", "IsSystem", "Name", "TenantId" },
                values: new object[,]
                {
                    { new Guid("00a062e6-62e6-42c5-b6b1-024328651b72"), "Tasks are not finished as reported or have any issues in al the tasks", true, "NCR", new Guid("b3466e83-7e11-464c-b93a-daf047838b26") },
                    { new Guid("030bb085-e230-4370-aec7-9a74d652864e"), "Confirm the tasks are actually finished as reported", true, "Approve", new Guid("b3466e83-7e11-464c-b93a-daf047838b26") },
                    { new Guid("2a1a5b96-cf93-4111-b4b1-76c19d6333b4"), "Not all tasks are actually finished as reported", true, "Partially Approve", new Guid("b3466e83-7e11-464c-b93a-daf047838b26") }
                });

            migrationBuilder.CreateIndex(
                name: "IX_TaskAllocations_ApprovedById",
                table: "TaskAllocations",
                column: "ApprovedById");

            migrationBuilder.CreateIndex(
                name: "IX_TaskAllocations_ReportedById",
                table: "TaskAllocations",
                column: "ReportedById");

            migrationBuilder.CreateIndex(
                name: "IX_TaskAllocations_WorkStatusId",
                table: "TaskAllocations",
                column: "WorkStatusId");

            migrationBuilder.CreateIndex(
                name: "IX_WorkStatusMasters_TenantId",
                table: "WorkStatusMasters",
                column: "TenantId");

            migrationBuilder.AddForeignKey(
                name: "FK_TaskAllocations_Employees_ApprovedById",
                table: "TaskAllocations",
                column: "ApprovedById",
                principalTable: "Employees",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_TaskAllocations_Employees_ReportedById",
                table: "TaskAllocations",
                column: "ReportedById",
                principalTable: "Employees",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_TaskAllocations_WorkStatusMasters_WorkStatusId",
                table: "TaskAllocations",
                column: "WorkStatusId",
                principalTable: "WorkStatusMasters",
                principalColumn: "Id");
        }

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

            migrationBuilder.DropForeignKey(
                name: "FK_TaskAllocations_Employees_ReportedById",
                table: "TaskAllocations");

            migrationBuilder.DropForeignKey(
                name: "FK_TaskAllocations_WorkStatusMasters_WorkStatusId",
                table: "TaskAllocations");

            migrationBuilder.DropTable(
                name: "WorkStatusMasters");

            migrationBuilder.DropIndex(
                name: "IX_TaskAllocations_ApprovedById",
                table: "TaskAllocations");

            migrationBuilder.DropIndex(
                name: "IX_TaskAllocations_ReportedById",
                table: "TaskAllocations");

            migrationBuilder.DropIndex(
                name: "IX_TaskAllocations_WorkStatusId",
                table: "TaskAllocations");

            migrationBuilder.DropColumn(
                name: "ApprovedById",
                table: "TaskAllocations");

            migrationBuilder.DropColumn(
                name: "ApprovedDate",
                table: "TaskAllocations");

            migrationBuilder.DropColumn(
                name: "ParentTaskId",
                table: "TaskAllocations");

            migrationBuilder.DropColumn(
                name: "ReportedById",
                table: "TaskAllocations");

            migrationBuilder.DropColumn(
                name: "ReportedTask",
                table: "TaskAllocations");

            migrationBuilder.DropColumn(
                name: "WorkStatusId",
                table: "TaskAllocations");
        }
    }
}
