<?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('investment_transactions', function (Blueprint $table): void {
            $table->text('admin_note')->nullable()->after('referral_source_transaction_id');
            $table->foreignId('created_by_user_id')->nullable()->after('admin_note')
                ->constrained('users')->nullOnDelete();
            $table->timestamp('reversed_at')->nullable()->after('created_by_user_id');
            $table->foreignId('reversed_by_user_id')->nullable()->after('reversed_at')
                ->constrained('users')->nullOnDelete();
            $table->foreignId('reversal_of_transaction_id')->nullable()->after('reversed_by_user_id')
                ->constrained('investment_transactions')->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('investment_transactions', function (Blueprint $table): void {
            $table->dropConstrainedForeignId('reversal_of_transaction_id');
            $table->dropConstrainedForeignId('reversed_by_user_id');
            $table->dropColumn('reversed_at');
            $table->dropConstrainedForeignId('created_by_user_id');
            $table->dropColumn('admin_note');
        });
    }
};
