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

            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->foreignId('user_account_id')->constrained('user_accounts')->onDelete('cascade');

            // investment = owner puts money in | drawing = owner takes money out
            $table->enum('type', ['investment','drawing']);

            $table->string('trx_no')->nullable()->index();
            $table->decimal('amount', 15, 2);
            $table->string('note')->nullable();
            $table->dateTime('posted_at')->nullable()->index();

            $table->timestamps();

            $table->index(['user_id','user_account_id']);
            $table->index(['user_id','type']);
        });
    }

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