using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class AddPaymentOrder : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "External_DanalLiveClientKeyEnc",
                table: "Config",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "External_DanalLiveCpid",
                table: "Config",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "External_DanalLiveSecretKeyEnc",
                table: "Config",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "External_DanalPayMode",
                table: "Config",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "External_DanalTestClientKeyEnc",
                table: "Config",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "External_DanalTestCpid",
                table: "Config",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "External_DanalTestSecretKeyEnc",
                table: "Config",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "Payment_DanalCardFeeAmount",
                table: "Config",
                type: "decimal(18,2)",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "Payment_DanalCardFeeRate",
                table: "Config",
                type: "decimal(18,2)",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "Payment_DanalSimpleFeeAmount",
                table: "Config",
                type: "decimal(18,2)",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "Payment_DanalSimpleFeeRate",
                table: "Config",
                type: "decimal(18,2)",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "Payment_DanalTransferFeeAmount",
                table: "Config",
                type: "decimal(18,2)",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "Payment_DanalTransferFeeRate",
                table: "Config",
                type: "decimal(18,2)",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "Payment_DanalVbankFeeAmount",
                table: "Config",
                type: "decimal(18,2)",
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "Payment_DanalVbankFeeRate",
                table: "Config",
                type: "decimal(18,2)",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "PaymentOrder",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    OrderId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
                    TransactionId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    Amount = table.Column<int>(type: "int", nullable: false),
                    PointAmount = table.Column<int>(type: "int", nullable: false),
                    VatAmount = table.Column<int>(type: "int", nullable: false),
                    PaymentMethod = table.Column<int>(type: "int", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    PaidAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CancelledAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    FailReason = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    VirtualAccountNumber = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: true),
                    VirtualAccountBank = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    VirtualAccountHolder = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true),
                    VirtualAccountExpireAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PaymentOrder", x => x.ID);
                    table.ForeignKey(
                        name: "FK_PaymentOrder_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "PG 결제 주문");

            migrationBuilder.CreateIndex(
                name: "IX_PaymentOrder_MemberID",
                table: "PaymentOrder",
                column: "MemberID");

            migrationBuilder.CreateIndex(
                name: "IX_PaymentOrder_OrderId",
                table: "PaymentOrder",
                column: "OrderId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_PaymentOrder_Status",
                table: "PaymentOrder",
                column: "Status");

            migrationBuilder.CreateIndex(
                name: "IX_PaymentOrder_TransactionId",
                table: "PaymentOrder",
                column: "TransactionId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "PaymentOrder");

            migrationBuilder.DropColumn(
                name: "External_DanalLiveClientKeyEnc",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "External_DanalLiveCpid",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "External_DanalLiveSecretKeyEnc",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "External_DanalPayMode",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "External_DanalTestClientKeyEnc",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "External_DanalTestCpid",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "External_DanalTestSecretKeyEnc",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "Payment_DanalCardFeeAmount",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "Payment_DanalCardFeeRate",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "Payment_DanalSimpleFeeAmount",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "Payment_DanalSimpleFeeRate",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "Payment_DanalTransferFeeAmount",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "Payment_DanalTransferFeeRate",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "Payment_DanalVbankFeeAmount",
                table: "Config");

            migrationBuilder.DropColumn(
                name: "Payment_DanalVbankFeeRate",
                table: "Config");
        }
    }
}
