<?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->foreignId('payment_method_id')
                ->nullable()
                ->after('liner_id')
                ->constrained('user_payment_methods')
                ->nullOnDelete();
        });

        Schema::table('payouts', function (Blueprint $table): void {
            $table->foreignId('payment_method_id')
                ->nullable()
                ->after('liner_id')
                ->constrained('user_payment_methods')
                ->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('payouts', function (Blueprint $table): void {
            $table->dropConstrainedForeignId('payment_method_id');
        });

        Schema::table('payments', function (Blueprint $table): void {
            $table->dropConstrainedForeignId('payment_method_id');
        });
    }
};
