<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('airtime_to_cash_requests', function (Blueprint $table) {
            $table->enum('payout_status', ['not_required', 'pending', 'paid', 'failed'])
                ->default('not_required')
                ->after('status');
            $table->string('payout_reference', 120)->nullable()->after('payout_status');
            $table->text('payout_failure_reason')->nullable()->after('payout_reference');
            $table->timestamp('payout_paid_at')->nullable()->after('payout_failure_reason');

            $table->index(['payout_status', 'updated_at'], 'atc_payout_queue_idx');
        });
    }

    public function down(): void
    {
        Schema::table('airtime_to_cash_requests', function (Blueprint $table) {
            $table->dropIndex('atc_payout_queue_idx');
            $table->dropColumn([
                'payout_status',
                'payout_reference',
                'payout_failure_reason',
                'payout_paid_at',
            ]);
        });
    }
};
