<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up()
    {
        Schema::table('withdraws', function (Blueprint $table) {
            if (!Schema::hasColumn('withdraws', 'channel')) {
                $table->string('channel')->nullable()->default('')->comment('提现通道');
            }
            if (!Schema::hasColumn('withdraws', 'order_no')) {
                $table->string('order_no')->nullable()->default('')->comment('商户订单号');
            }
            if (!Schema::hasColumn('withdraws', 'pay_no')) {
                $table->string('pay_no')->nullable()->default('')->comment('三方订单号');
            }
            if (!Schema::hasColumn('withdraws', 'pay_data')) {
                $table->text('pay_data')->nullable()->comment('三方下单响应');
            }
            if (!Schema::hasColumn('withdraws', 'callback_data')) {
                $table->text('callback_data')->nullable()->comment('三方回调数据');
            }
        });
    }

    public function down()
    {
        Schema::table('withdraws', function (Blueprint $table) {
            foreach (['channel', 'order_no', 'pay_no', 'pay_data', 'callback_data'] as $column) {
                if (Schema::hasColumn('withdraws', $column)) {
                    $table->dropColumn($column);
                }
            }
        });
    }
};
