<?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('payments', function (Blueprint $table): void {
            $table->string('provider_reference')->nullable()->after('provider');
            $table->text('failure_reason')->nullable()->after('provider_reference');
            $table->index('provider_reference');
        });

        Schema::table('payouts', function (Blueprint $table): void {
            $table->string('provider_reference')->nullable()->after('provider');
            $table->text('failure_reason')->nullable()->after('provider_reference');
            $table->index('provider_reference');
        });
    }

    public function down(): void
    {
        Schema::table('payouts', function (Blueprint $table): void {
            $table->dropIndex(['provider_reference']);
            $table->dropColumn(['provider_reference', 'failure_reason']);
        });

        Schema::table('payments', function (Blueprint $table): void {
            $table->dropIndex(['provider_reference']);
            $table->dropColumn(['provider_reference', 'failure_reason']);
        });
    }
};
