using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CMSMicroservice.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class AddUserPackagePurchase : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "UserPackagePurchases",
                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),
                    PackageId = table.Column<long>(type: "bigint", nullable: false),
                    PurchaseMethod = table.Column<int>(type: "int", nullable: false),
                    PurchasedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Amount = table.Column<long>(type: "bigint", nullable: false),
                    OrderId = table.Column<long>(type: "bigint", nullable: true),
                    TransactionId = table.Column<long>(type: "bigint", nullable: true),
                    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_UserPackagePurchases", x => x.Id);
                    table.ForeignKey(
                        name: "FK_UserPackagePurchases_Packages_PackageId",
                        column: x => x.PackageId,
                        principalSchema: "CMS",
                        principalTable: "Packages",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_UserPackagePurchases_Transactionss_TransactionId",
                        column: x => x.TransactionId,
                        principalSchema: "CMS",
                        principalTable: "Transactionss",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_UserPackagePurchases_UserOrders_OrderId",
                        column: x => x.OrderId,
                        principalSchema: "CMS",
                        principalTable: "UserOrders",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_UserPackagePurchases_Users_UserId",
                        column: x => x.UserId,
                        principalSchema: "CMS",
                        principalTable: "Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_UserPackagePurchase_PackageId",
                schema: "CMS",
                table: "UserPackagePurchases",
                column: "PackageId");

            migrationBuilder.CreateIndex(
                name: "IX_UserPackagePurchase_PurchasedAt",
                schema: "CMS",
                table: "UserPackagePurchases",
                column: "PurchasedAt");

            migrationBuilder.CreateIndex(
                name: "IX_UserPackagePurchase_UserId",
                schema: "CMS",
                table: "UserPackagePurchases",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_UserPackagePurchase_UserId_PurchasedAt",
                schema: "CMS",
                table: "UserPackagePurchases",
                columns: new[] { "UserId", "PurchasedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_UserPackagePurchases_OrderId",
                schema: "CMS",
                table: "UserPackagePurchases",
                column: "OrderId");

            migrationBuilder.CreateIndex(
                name: "IX_UserPackagePurchases_TransactionId",
                schema: "CMS",
                table: "UserPackagePurchases",
                column: "TransactionId");
        }

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