<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('ledger_transactions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->string('type'); // 'trade', 'deposit', 'withdrawal', 'fee', 'investment', etc.
            $table->text('description');
            $table->decimal('amount', 20, 8);
            $table->string('currency', 10);
            $table->enum('status', ['pending', 'completed', 'failed', 'reversed'])->default('pending');
            $table->json('details')->nullable(); // Additional details specific to transaction type
            $table->timestamps();
            
            $table->index(['user_id']);
            $table->index(['type']);
            $table->index(['currency']);
            $table->index(['status']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('ledger_transactions');
    }
};