using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CMSMicroservice.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class u16 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_CommissionPayoutHistories_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "CommissionPayoutHistories");

            migrationBuilder.DropForeignKey(
                name: "FK_NetworkWeeklyBalances_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "NetworkWeeklyBalances");

            migrationBuilder.DropForeignKey(
                name: "FK_UserCommissionPayouts_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "UserCommissionPayouts");

            migrationBuilder.DropForeignKey(
                name: "FK_WeeklyCommissionPools_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "WeeklyCommissionPools");

            migrationBuilder.DropForeignKey(
                name: "FK_WorkerExecutionLogs_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "WorkerExecutionLogs");

            migrationBuilder.DropIndex(
                name: "IX_WorkerExecutionLogs_WeekNumber",
                schema: "CMS",
                table: "WorkerExecutionLogs");

            migrationBuilder.DropIndex(
                name: "IX_WeeklyCommissionPool_WeekDefinitionId",
                schema: "CMS",
                table: "WeeklyCommissionPools");

            migrationBuilder.DropIndex(
                name: "IX_WeeklyCommissionPool_WeekNumber",
                schema: "CMS",
                table: "WeeklyCommissionPools");

            migrationBuilder.DropIndex(
                name: "IX_UserCommissionPayout_UserId_WeekNumber",
                schema: "CMS",
                table: "UserCommissionPayouts");

            migrationBuilder.DropIndex(
                name: "IX_UserCommissionPayout_WeekNumber",
                schema: "CMS",
                table: "UserCommissionPayouts");

            migrationBuilder.DropIndex(
                name: "IX_NetworkWeeklyBalance_UserId_WeekNumber",
                schema: "CMS",
                table: "NetworkWeeklyBalances");

            migrationBuilder.DropIndex(
                name: "IX_NetworkWeeklyBalance_WeekNumber",
                schema: "CMS",
                table: "NetworkWeeklyBalances");

            migrationBuilder.DropIndex(
                name: "IX_CommissionPayoutHistory_WeekNumber",
                schema: "CMS",
                table: "CommissionPayoutHistories");

            migrationBuilder.DropColumn(
                name: "WeekNumber",
                schema: "CMS",
                table: "WorkerExecutionLogs");

            migrationBuilder.DropColumn(
                name: "WeekNumber",
                schema: "CMS",
                table: "WeeklyCommissionPools");

            migrationBuilder.DropColumn(
                name: "WeekNumber",
                schema: "CMS",
                table: "UserCommissionPayouts");

            migrationBuilder.DropColumn(
                name: "WeekNumber",
                schema: "CMS",
                table: "NetworkWeeklyBalances");

            migrationBuilder.DropColumn(
                name: "WeekNumber",
                schema: "CMS",
                table: "CommissionPayoutHistories");

            migrationBuilder.RenameIndex(
                name: "IX_UserCommissionPayout_WeekDefinitionId",
                schema: "CMS",
                table: "UserCommissionPayouts",
                newName: "IX_UserCommissionPayouts_WeekDefinitionId");

            migrationBuilder.AlterColumn<long>(
                name: "WeekDefinitionId",
                schema: "CMS",
                table: "WorkerExecutionLogs",
                type: "bigint",
                nullable: false,
                defaultValue: 0L,
                oldClrType: typeof(long),
                oldType: "bigint",
                oldNullable: true);

            migrationBuilder.AlterColumn<long>(
                name: "WeekDefinitionId",
                schema: "CMS",
                table: "WeeklyCommissionPools",
                type: "bigint",
                nullable: false,
                defaultValue: 0L,
                oldClrType: typeof(long),
                oldType: "bigint",
                oldNullable: true);

            migrationBuilder.AlterColumn<long>(
                name: "WeekDefinitionId",
                schema: "CMS",
                table: "UserCommissionPayouts",
                type: "bigint",
                nullable: false,
                defaultValue: 0L,
                oldClrType: typeof(long),
                oldType: "bigint",
                oldNullable: true);

            migrationBuilder.AlterColumn<long>(
                name: "WeekDefinitionId",
                schema: "CMS",
                table: "NetworkWeeklyBalances",
                type: "bigint",
                nullable: false,
                defaultValue: 0L,
                oldClrType: typeof(long),
                oldType: "bigint",
                oldNullable: true);

            migrationBuilder.AlterColumn<long>(
                name: "WeekDefinitionId",
                schema: "CMS",
                table: "CommissionPayoutHistories",
                type: "bigint",
                nullable: false,
                defaultValue: 0L,
                oldClrType: typeof(long),
                oldType: "bigint",
                oldNullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_WeeklyCommissionPool_WeekDefinitionId",
                schema: "CMS",
                table: "WeeklyCommissionPools",
                column: "WeekDefinitionId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_UserCommissionPayout_UserId_WeekDefinitionId",
                schema: "CMS",
                table: "UserCommissionPayouts",
                columns: new[] { "UserId", "WeekDefinitionId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_NetworkWeeklyBalance_UserId_WeekDefinitionId",
                schema: "CMS",
                table: "NetworkWeeklyBalances",
                columns: new[] { "UserId", "WeekDefinitionId" },
                unique: true);

            migrationBuilder.AddForeignKey(
                name: "FK_CommissionPayoutHistories_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "CommissionPayoutHistories",
                column: "WeekDefinitionId",
                principalSchema: "CMS",
                principalTable: "WeekDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_NetworkWeeklyBalances_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "NetworkWeeklyBalances",
                column: "WeekDefinitionId",
                principalSchema: "CMS",
                principalTable: "WeekDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_UserCommissionPayouts_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "UserCommissionPayouts",
                column: "WeekDefinitionId",
                principalSchema: "CMS",
                principalTable: "WeekDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_WeeklyCommissionPools_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "WeeklyCommissionPools",
                column: "WeekDefinitionId",
                principalSchema: "CMS",
                principalTable: "WeekDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_WorkerExecutionLogs_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "WorkerExecutionLogs",
                column: "WeekDefinitionId",
                principalSchema: "CMS",
                principalTable: "WeekDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_CommissionPayoutHistories_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "CommissionPayoutHistories");

            migrationBuilder.DropForeignKey(
                name: "FK_NetworkWeeklyBalances_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "NetworkWeeklyBalances");

            migrationBuilder.DropForeignKey(
                name: "FK_UserCommissionPayouts_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "UserCommissionPayouts");

            migrationBuilder.DropForeignKey(
                name: "FK_WeeklyCommissionPools_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "WeeklyCommissionPools");

            migrationBuilder.DropForeignKey(
                name: "FK_WorkerExecutionLogs_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "WorkerExecutionLogs");

            migrationBuilder.DropIndex(
                name: "IX_WeeklyCommissionPool_WeekDefinitionId",
                schema: "CMS",
                table: "WeeklyCommissionPools");

            migrationBuilder.DropIndex(
                name: "IX_UserCommissionPayout_UserId_WeekDefinitionId",
                schema: "CMS",
                table: "UserCommissionPayouts");

            migrationBuilder.DropIndex(
                name: "IX_NetworkWeeklyBalance_UserId_WeekDefinitionId",
                schema: "CMS",
                table: "NetworkWeeklyBalances");

            migrationBuilder.RenameIndex(
                name: "IX_UserCommissionPayouts_WeekDefinitionId",
                schema: "CMS",
                table: "UserCommissionPayouts",
                newName: "IX_UserCommissionPayout_WeekDefinitionId");

            migrationBuilder.AlterColumn<long>(
                name: "WeekDefinitionId",
                schema: "CMS",
                table: "WorkerExecutionLogs",
                type: "bigint",
                nullable: true,
                oldClrType: typeof(long),
                oldType: "bigint");

            migrationBuilder.AddColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "WorkerExecutionLogs",
                type: "nvarchar(10)",
                maxLength: 10,
                nullable: false,
                defaultValue: "");

            migrationBuilder.AlterColumn<long>(
                name: "WeekDefinitionId",
                schema: "CMS",
                table: "WeeklyCommissionPools",
                type: "bigint",
                nullable: true,
                oldClrType: typeof(long),
                oldType: "bigint");

            migrationBuilder.AddColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "WeeklyCommissionPools",
                type: "nvarchar(10)",
                maxLength: 10,
                nullable: false,
                defaultValue: "");

            migrationBuilder.AlterColumn<long>(
                name: "WeekDefinitionId",
                schema: "CMS",
                table: "UserCommissionPayouts",
                type: "bigint",
                nullable: true,
                oldClrType: typeof(long),
                oldType: "bigint");

            migrationBuilder.AddColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "UserCommissionPayouts",
                type: "nvarchar(10)",
                maxLength: 10,
                nullable: false,
                defaultValue: "");

            migrationBuilder.AlterColumn<long>(
                name: "WeekDefinitionId",
                schema: "CMS",
                table: "NetworkWeeklyBalances",
                type: "bigint",
                nullable: true,
                oldClrType: typeof(long),
                oldType: "bigint");

            migrationBuilder.AddColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "NetworkWeeklyBalances",
                type: "nvarchar(10)",
                maxLength: 10,
                nullable: false,
                defaultValue: "");

            migrationBuilder.AlterColumn<long>(
                name: "WeekDefinitionId",
                schema: "CMS",
                table: "CommissionPayoutHistories",
                type: "bigint",
                nullable: true,
                oldClrType: typeof(long),
                oldType: "bigint");

            migrationBuilder.AddColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "CommissionPayoutHistories",
                type: "nvarchar(10)",
                maxLength: 10,
                nullable: false,
                defaultValue: "");

            migrationBuilder.CreateIndex(
                name: "IX_WorkerExecutionLogs_WeekNumber",
                schema: "CMS",
                table: "WorkerExecutionLogs",
                column: "WeekNumber");

            migrationBuilder.CreateIndex(
                name: "IX_WeeklyCommissionPool_WeekDefinitionId",
                schema: "CMS",
                table: "WeeklyCommissionPools",
                column: "WeekDefinitionId");

            migrationBuilder.CreateIndex(
                name: "IX_WeeklyCommissionPool_WeekNumber",
                schema: "CMS",
                table: "WeeklyCommissionPools",
                column: "WeekNumber",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_UserCommissionPayout_UserId_WeekNumber",
                schema: "CMS",
                table: "UserCommissionPayouts",
                columns: new[] { "UserId", "WeekNumber" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_UserCommissionPayout_WeekNumber",
                schema: "CMS",
                table: "UserCommissionPayouts",
                column: "WeekNumber");

            migrationBuilder.CreateIndex(
                name: "IX_NetworkWeeklyBalance_UserId_WeekNumber",
                schema: "CMS",
                table: "NetworkWeeklyBalances",
                columns: new[] { "UserId", "WeekNumber" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_NetworkWeeklyBalance_WeekNumber",
                schema: "CMS",
                table: "NetworkWeeklyBalances",
                column: "WeekNumber");

            migrationBuilder.CreateIndex(
                name: "IX_CommissionPayoutHistory_WeekNumber",
                schema: "CMS",
                table: "CommissionPayoutHistories",
                column: "WeekNumber");

            migrationBuilder.AddForeignKey(
                name: "FK_CommissionPayoutHistories_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "CommissionPayoutHistories",
                column: "WeekDefinitionId",
                principalSchema: "CMS",
                principalTable: "WeekDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);

            migrationBuilder.AddForeignKey(
                name: "FK_NetworkWeeklyBalances_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "NetworkWeeklyBalances",
                column: "WeekDefinitionId",
                principalSchema: "CMS",
                principalTable: "WeekDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);

            migrationBuilder.AddForeignKey(
                name: "FK_UserCommissionPayouts_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "UserCommissionPayouts",
                column: "WeekDefinitionId",
                principalSchema: "CMS",
                principalTable: "WeekDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);

            migrationBuilder.AddForeignKey(
                name: "FK_WeeklyCommissionPools_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "WeeklyCommissionPools",
                column: "WeekDefinitionId",
                principalSchema: "CMS",
                principalTable: "WeekDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);

            migrationBuilder.AddForeignKey(
                name: "FK_WorkerExecutionLogs_WeekDefinitions_WeekDefinitionId",
                schema: "CMS",
                table: "WorkerExecutionLogs",
                column: "WeekDefinitionId",
                principalSchema: "CMS",
                principalTable: "WeekDefinitions",
                principalColumn: "Id",
                onDelete: ReferentialAction.SetNull);
        }
    }
}
