using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Marco.Pms.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class Added_Promoter_And_PMC_In_Project_Table_As_Forgin_Key : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Employees_Tenants_TenantId",
                table: "Employees");

            migrationBuilder.AddColumn<Guid>(
                name: "PMCId",
                table: "Projects",
                type: "char(36)",
                nullable: false,
                defaultValue: new Guid("4e3a6d31-c640-40f7-8d67-6c109fcdb9ea"),
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<Guid>(
                name: "PromoterId",
                table: "Projects",
                type: "char(36)",
                nullable: false,
                defaultValue: new Guid("4e3a6d31-c640-40f7-8d67-6c109fcdb9ea"),
                collation: "ascii_general_ci");

            migrationBuilder.AlterColumn<Guid>(
                name: "TenantId",
                table: "Employees",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)")
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.UpdateData(
                table: "Projects",
                keyColumn: "Id",
                keyValue: new Guid("85bf587b-7ca9-4685-b77c-d817f5847e85"),
                columns: new[] { "PMCId", "PromoterId" },
                values: new object[] { new Guid("4e3a6d31-c640-40f7-8d67-6c109fcdb9ea"), new Guid("4e3a6d31-c640-40f7-8d67-6c109fcdb9ea") });

            migrationBuilder.CreateIndex(
                name: "IX_Projects_PMCId",
                table: "Projects",
                column: "PMCId");

            migrationBuilder.CreateIndex(
                name: "IX_Projects_PromoterId",
                table: "Projects",
                column: "PromoterId");

            migrationBuilder.AddForeignKey(
                name: "FK_Employees_Tenants_TenantId",
                table: "Employees",
                column: "TenantId",
                principalTable: "Tenants",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_Projects_Organizations_PMCId",
                table: "Projects",
                column: "PMCId",
                principalTable: "Organizations",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Projects_Organizations_PromoterId",
                table: "Projects",
                column: "PromoterId",
                principalTable: "Organizations",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

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

            migrationBuilder.DropForeignKey(
                name: "FK_Projects_Organizations_PMCId",
                table: "Projects");

            migrationBuilder.DropForeignKey(
                name: "FK_Projects_Organizations_PromoterId",
                table: "Projects");

            migrationBuilder.DropIndex(
                name: "IX_Projects_PMCId",
                table: "Projects");

            migrationBuilder.DropIndex(
                name: "IX_Projects_PromoterId",
                table: "Projects");

            migrationBuilder.DropColumn(
                name: "PMCId",
                table: "Projects");

            migrationBuilder.DropColumn(
                name: "PromoterId",
                table: "Projects");

            migrationBuilder.AlterColumn<Guid>(
                name: "TenantId",
                table: "Employees",
                type: "char(36)",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
                collation: "ascii_general_ci",
                oldClrType: typeof(Guid),
                oldType: "char(36)",
                oldNullable: true)
                .OldAnnotation("Relational:Collation", "ascii_general_ci");

            migrationBuilder.AddForeignKey(
                name: "FK_Employees_Tenants_TenantId",
                table: "Employees",
                column: "TenantId",
                principalTable: "Tenants",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
