<?php

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

return new class extends Migration
{
    public function up(): void
    {
        if (!Schema::hasTable('users')) {
            return;
        }

        if (!Schema::hasColumn('users', 'withdraw_hold')) {
            Schema::table('users', function (Blueprint $table) {
                $table->boolean('withdraw_hold')->default(false)->after('is_banned');
            });
        }

        DB::table('users')->update(['withdraw_hold' => 0]);
    }

    public function down(): void
    {
        if (!Schema::hasTable('users') || !Schema::hasColumn('users', 'withdraw_hold')) {
            return;
        }

        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('withdraw_hold');
        });
    }
};
