<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('member_ledgers', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('hashkey', 300)->unique();
            $table->bigInteger('user_id')->index();
            $table->bigInteger('organization_id')->index()->nullable(); // Nullable if it's a platform-wide balance
            $table->decimal('amount', 15, 2);
            $table->string('transaction_type'); // SHARE_CAPITAL, SAVINGS, DIVIDEND, TOP_UP, WITHDRAWAL, PURCHASE
            $table->enum('flow', ['IN', 'OUT']);
            $table->decimal('balance_after', 15, 2);
            $table->text('description')->nullable();
            $table->string('reference_id')->nullable(); // e.g., global_transaction hashkey
            $table->bigInteger('created_by')->nullable();
            $table->bigInteger('updated_by')->nullable();
            $table->boolean('is_active')->default(true);
            $table->datetimes();
        });
    }

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