<?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_entries', function (Blueprint $table) {
            $table->id();
            $table->foreignId('ledger_transaction_id')->constrained()->onDelete('cascade');
            $table->unsignedBigInteger('account_id'); // Could be user ID or system account ID
            $table->enum('entry_type', ['debit', 'credit']);
            $table->decimal('amount', 20, 8);
            $table->string('currency', 10);
            $table->text('description');
            $table->json('metadata')->nullable(); // Additional metadata for the entry
            $table->timestamps();
            
            $table->index(['ledger_transaction_id']);
            $table->index(['account_id']);
            $table->index(['entry_type']);
            $table->index(['currency']);
        });
    }

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