<?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->foreignId('provider_withdrawal_id')
                ->nullable()
                ->after('provider_id')
                ->constrained('provider_withdrawals')
                ->nullOnDelete();

            $table->index('provider_withdrawal_id');
        });
    }

    public function down(): void
    {
        Schema::table('payment_splits', function (Blueprint $table) {
            $table->dropForeign(['provider_withdrawal_id']);
            $table->dropIndex(['provider_withdrawal_id']);
            $table->dropColumn('provider_withdrawal_id');
        });
    }
};
