<?php

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

return new class extends Migration
{
    public function up(): void
    {
        if (! Schema::hasTable('settlement_batches')
            || Schema::hasColumn('settlement_batches', 'auto_payout_attempts')) {
            return;
        }

        Schema::table('settlement_batches', function (Blueprint $table): void {
            $table->unsignedInteger('auto_payout_attempts')->default(0)->after('paid_at');
        });
    }

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

        Schema::table('settlement_batches', function (Blueprint $table): void {
            $table->dropColumn('auto_payout_attempts');
        });
    }
};
