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

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

            $table->foreignId('from_account_id')->constrained('user_accounts')->onDelete('cascade');
            $table->foreignId('to_account_id')->constrained('user_accounts')->onDelete('cascade');

            $table->decimal('amount', 15, 2);
            $table->decimal('bank_charge', 15, 2)->nullable(); // ✅ optional

            $table->string('note')->nullable();
            $table->string('trx_no')->nullable();
            $table->dateTime('posted_at')->nullable();

            $table->timestamps();

            $table->index(['user_id','from_account_id']);
            $table->index(['user_id','to_account_id']);
        });
    }

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