<?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::create('wallet_transactions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->string('type', 50); // deposit, withdrawal, profit, commission, fee, charge, purchase, sale
            $table->decimal('amount', 19, 0);
            $table->decimal('balance_after', 19, 0)->nullable();
            $table->string('description')->nullable();
            $table->string('tracking_code', 100)->nullable();
            $table->string('status', 30)->default('completed'); // pending, completed, failed, cancelled
            $table->foreignId('payment_id')->nullable()->constrained('payments')->nullOnDelete();
            $table->foreignId('project_id')->nullable()->constrained('projects')->nullOnDelete();
            $table->json('meta')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('wallet_transactions');
    }
};
