using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CMSMicroservice.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class u21 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<DateTime>(
                name: "MagicActivatedAt",
                schema: "CMS",
                table: "UserWallets",
                type: "datetime2",
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "MagicCompletedAt",
                schema: "CMS",
                table: "UserWallets",
                type: "datetime2",
                nullable: true);

            migrationBuilder.AddColumn<long>(
                name: "MagicTotalCredited",
                schema: "CMS",
                table: "UserWallets",
                type: "bigint",
                nullable: false,
                defaultValue: 0L);

            migrationBuilder.AddColumn<long>(
                name: "MagicTotalDeposited",
                schema: "CMS",
                table: "UserWallets",
                type: "bigint",
                nullable: false,
                defaultValue: 0L);

            migrationBuilder.AddColumn<int>(
                name: "WalletMode",
                schema: "CMS",
                table: "UserWallets",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "ClubMembershipCycles",
                schema: "CMS",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    UserId = table.Column<long>(type: "bigint", nullable: false),
                    ClubMembershipId = table.Column<long>(type: "bigint", nullable: false),
                    CycleNumber = table.Column<int>(type: "int", nullable: false),
                    PackagePurchasedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    MagicStartedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    MagicCompletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    PurchaseMethod = table.Column<int>(type: "int", nullable: false),
                    PackageAmount = table.Column<long>(type: "bigint", nullable: false),
                    IsCurrentCycle = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    Created = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifiedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ClubMembershipCycles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ClubMembershipCycles_ClubMemberships_ClubMembershipId",
                        column: x => x.ClubMembershipId,
                        principalSchema: "CMS",
                        principalTable: "ClubMemberships",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_ClubMembershipCycles_Users_UserId",
                        column: x => x.UserId,
                        principalSchema: "CMS",
                        principalTable: "Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_ClubMembershipCycle_PackagePurchasedAt",
                schema: "CMS",
                table: "ClubMembershipCycles",
                column: "PackagePurchasedAt");

            migrationBuilder.CreateIndex(
                name: "IX_ClubMembershipCycle_UserId_IsCurrentCycle",
                schema: "CMS",
                table: "ClubMembershipCycles",
                columns: new[] { "UserId", "IsCurrentCycle" });

            migrationBuilder.CreateIndex(
                name: "IX_ClubMembershipCycles_ClubMembershipId",
                schema: "CMS",
                table: "ClubMembershipCycles",
                column: "ClubMembershipId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ClubMembershipCycles",
                schema: "CMS");

            migrationBuilder.DropColumn(
                name: "MagicActivatedAt",
                schema: "CMS",
                table: "UserWallets");

            migrationBuilder.DropColumn(
                name: "MagicCompletedAt",
                schema: "CMS",
                table: "UserWallets");

            migrationBuilder.DropColumn(
                name: "MagicTotalCredited",
                schema: "CMS",
                table: "UserWallets");

            migrationBuilder.DropColumn(
                name: "MagicTotalDeposited",
                schema: "CMS",
                table: "UserWallets");

            migrationBuilder.DropColumn(
                name: "WalletMode",
                schema: "CMS",
                table: "UserWallets");
        }
    }
}
