<?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('gts_wallet_transactions', function (Blueprint $table): void {
            if (! Schema::hasColumn('gts_wallet_transactions', 'payment_method_id')) {
                $table->foreignId('payment_method_id')->nullable()->after('gts_wallet_id')->constrained()->nullOnDelete();
            }

            if (! Schema::hasColumn('gts_wallet_transactions', 'sender_account')) {
                $table->string('sender_account')->nullable()->after('reference');
            }

            if (! Schema::hasColumn('gts_wallet_transactions', 'proof_path')) {
                $table->string('proof_path')->nullable()->after('sender_account');
            }
        });
    }

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

            if (Schema::hasColumn('gts_wallet_transactions', 'sender_account')) {
                $table->dropColumn('sender_account');
            }

            if (Schema::hasColumn('gts_wallet_transactions', 'proof_path')) {
                $table->dropColumn('proof_path');
            }
        });
    }
};
