using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CMSMicroservice.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class AddWeekDefinitionIdToCommissionTables : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<long>(
                name: "WeekDefinitionId",
                schema: "CMS",
                table: "WorkerExecutionLogs",
                type: "bigint",
                nullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "WeeklyCommissionPools",
                type: "nvarchar(10)",
                maxLength: 10,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(20)",
                oldMaxLength: 20);

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

            migrationBuilder.AlterColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "UserCommissionPayouts",
                type: "nvarchar(10)",
                maxLength: 10,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(20)",
                oldMaxLength: 20);

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

            migrationBuilder.AlterColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "NetworkWeeklyBalances",
                type: "nvarchar(10)",
                maxLength: 10,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(20)",
                oldMaxLength: 20);

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

            migrationBuilder.AlterColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "CommissionPayoutHistories",
                type: "nvarchar(10)",
                maxLength: 10,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(20)",
                oldMaxLength: 20);

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

            migrationBuilder.CreateIndex(
                name: "IX_WorkerExecutionLogs_WeekDefinitionId",
                schema: "CMS",
                table: "WorkerExecutionLogs",
                column: "WeekDefinitionId");

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

            migrationBuilder.CreateIndex(
                name: "IX_UserCommissionPayout_WeekDefinitionId",
                schema: "CMS",
                table: "UserCommissionPayouts",
                column: "WeekDefinitionId");

            migrationBuilder.CreateIndex(
                name: "IX_NetworkWeeklyBalance_WeekDefinitionId",
                schema: "CMS",
                table: "NetworkWeeklyBalances",
                column: "WeekDefinitionId");

            migrationBuilder.CreateIndex(
                name: "IX_CommissionPayoutHistory_WeekDefinitionId",
                schema: "CMS",
                table: "CommissionPayoutHistories",
                column: "WeekDefinitionId");

            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);
        }

        /// <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_WorkerExecutionLogs_WeekDefinitionId",
                schema: "CMS",
                table: "WorkerExecutionLogs");

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

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

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

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

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

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

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

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

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

            migrationBuilder.AlterColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "WeeklyCommissionPools",
                type: "nvarchar(20)",
                maxLength: 20,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(10)",
                oldMaxLength: 10);

            migrationBuilder.AlterColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "UserCommissionPayouts",
                type: "nvarchar(20)",
                maxLength: 20,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(10)",
                oldMaxLength: 10);

            migrationBuilder.AlterColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "NetworkWeeklyBalances",
                type: "nvarchar(20)",
                maxLength: 20,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(10)",
                oldMaxLength: 10);

            migrationBuilder.AlterColumn<string>(
                name: "WeekNumber",
                schema: "CMS",
                table: "CommissionPayoutHistories",
                type: "nvarchar(20)",
                maxLength: 20,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(10)",
                oldMaxLength: 10);
        }
    }
}
