<?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('financial_events', function (Blueprint $table) {
            $table->id();

            $table->string('type'); // deposit|withdrawal|interest|loan_deposit|earn_deposit
            $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();

            $table->decimal('amount_usd', 30, 8)->nullable();
            $table->string('currency')->nullable();

            // Generic reference to related application.
            $table->string('reference_type')->nullable();
            $table->unsignedBigInteger('reference_id')->nullable();

            $table->json('metadata')->nullable();
            $table->timestamp('occurred_at')->nullable();

            $table->timestamps();
        });
    }

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