using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace CMSMicroservice.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class AddManualPaymentSystem : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "ManualPayments",
                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),
                    Amount = table.Column<long>(type: "bigint", nullable: false),
                    Type = table.Column<int>(type: "int", nullable: false),
                    Description = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: false),
                    ReferenceNumber = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
                    Status = table.Column<int>(type: "int", nullable: false),
                    RequestedBy = table.Column<long>(type: "bigint", nullable: false),
                    ApprovedBy = table.Column<long>(type: "bigint", nullable: true),
                    ApprovedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    RejectionReason = table.Column<string>(type: "nvarchar(500)", maxLength: 500, 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_ManualPayments", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ManualPayments_Transactionss_TransactionId",
                        column: x => x.TransactionId,
                        principalSchema: "CMS",
                        principalTable: "Transactionss",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_ManualPayments_Users_UserId",
                        column: x => x.UserId,
                        principalSchema: "CMS",
                        principalTable: "Users",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                });

            migrationBuilder.CreateIndex(
                name: "IX_ManualPayments_ApprovedBy",
                schema: "CMS",
                table: "ManualPayments",
                column: "ApprovedBy");

            migrationBuilder.CreateIndex(
                name: "IX_ManualPayments_Created",
                schema: "CMS",
                table: "ManualPayments",
                column: "Created");

            migrationBuilder.CreateIndex(
                name: "IX_ManualPayments_RequestedBy",
                schema: "CMS",
                table: "ManualPayments",
                column: "RequestedBy");

            migrationBuilder.CreateIndex(
                name: "IX_ManualPayments_Status",
                schema: "CMS",
                table: "ManualPayments",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_ManualPayments_TransactionId",
                schema: "CMS",
                table: "ManualPayments",
                column: "TransactionId");

            migrationBuilder.CreateIndex(
                name: "IX_ManualPayments_UserId",
                schema: "CMS",
                table: "ManualPayments",
                column: "UserId");

            migrationBuilder.CreateIndex(
                name: "IX_ManualPayments_UserId_Status",
                schema: "CMS",
                table: "ManualPayments",
                columns: new[] { "UserId", "Status" });
        }

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