using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Infrastructure.Migrations.AppDb
{
    /// <inheritdoc />
    public partial class AddSettlementAccountAndWithdrawalRequest : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "SettlementAccount",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ChannelID = table.Column<int>(type: "int", nullable: false),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    BankCode = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
                    BankName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    AccountNumber = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
                    AccountHolder = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    IsVerified = table.Column<bool>(type: "bit", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SettlementAccount", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SettlementAccount_Channel_ChannelID",
                        column: x => x.ChannelID,
                        principalTable: "Channel",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SettlementAccount_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "정산 계좌");

            migrationBuilder.CreateTable(
                name: "WithdrawalRequest",
                columns: table => new
                {
                    ID = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    ChannelID = table.Column<int>(type: "int", nullable: false),
                    MemberID = table.Column<int>(type: "int", nullable: false),
                    RequestedAmount = table.Column<int>(type: "int", nullable: false),
                    IncomeTax = table.Column<int>(type: "int", nullable: false),
                    LocalTax = table.Column<int>(type: "int", nullable: false),
                    WithholdingTax = table.Column<int>(type: "int", nullable: false),
                    NetAmount = table.Column<int>(type: "int", nullable: false),
                    Status = table.Column<int>(type: "int", nullable: false),
                    BankCode = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
                    BankName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    AccountNumber = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false),
                    AccountHolder = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
                    RequestedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    ProcessedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    RejectedReason = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    AdminMemo = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WithdrawalRequest", x => x.ID);
                    table.ForeignKey(
                        name: "FK_WithdrawalRequest_Channel_ChannelID",
                        column: x => x.ChannelID,
                        principalTable: "Channel",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_WithdrawalRequest_Member_MemberID",
                        column: x => x.MemberID,
                        principalTable: "Member",
                        principalColumn: "ID");
                },
                comment: "출금 요청");

            migrationBuilder.CreateIndex(
                name: "IX_SettlementAccount_ChannelID_MemberID",
                table: "SettlementAccount",
                columns: new[] { "ChannelID", "MemberID" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_SettlementAccount_MemberID",
                table: "SettlementAccount",
                column: "MemberID");

            migrationBuilder.CreateIndex(
                name: "IX_WithdrawalRequest_ChannelID",
                table: "WithdrawalRequest",
                column: "ChannelID");

            migrationBuilder.CreateIndex(
                name: "IX_WithdrawalRequest_MemberID_RequestedAt",
                table: "WithdrawalRequest",
                columns: new[] { "MemberID", "RequestedAt" });

            migrationBuilder.CreateIndex(
                name: "IX_WithdrawalRequest_MemberID_Status",
                table: "WithdrawalRequest",
                columns: new[] { "MemberID", "Status" });
        }

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

            migrationBuilder.DropTable(
                name: "WithdrawalRequest");
        }
    }
}
