<?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('payment_splits', function (Blueprint $table) {
            $table->dropIndex('payment_transfers_gateway_entity_reference_index');
            $table->dropIndex('payment_transfers_gateway_operation_reference_index');
            $table->dropIndex('payment_transfers_gateway_parent_reference_index');

            $table->dropColumn([
                'gateway_entity_reference',
                'gateway_entity_label',
                'gateway_operation_reference',
                'gateway_operation_label',
                'gateway_parent_reference',
                'gateway_parent_label',
                'failed_at',
                'failure_code',
                'failure_message',
                'gateway_payload',
            ]);
        });
    }

    public function down(): void
    {
        Schema::table('payment_splits', function (Blueprint $table) {
            $table->string('gateway_entity_reference')->nullable();
            $table->string('gateway_entity_label')->nullable();
            $table->string('gateway_operation_reference')->nullable();
            $table->string('gateway_operation_label')->nullable();
            $table->string('gateway_parent_reference')->nullable();
            $table->string('gateway_parent_label')->nullable();
            $table->timestamp('failed_at')->nullable();
            $table->string('failure_code')->nullable();
            $table->text('failure_message')->nullable();
            $table->json('gateway_payload')->nullable();

            $table->index('gateway_entity_reference');
            $table->index('gateway_operation_reference');
            $table->index('gateway_parent_reference');
        });
    }
};
