<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('financial_movements', function (Blueprint $table) {
            $table->id();
            $table->dateTime('date');
            $table->foreignId('origin_id')->constrained('banks')->cascadeOnUpdate();
            $table->foreignId('destination_id')->constrained('banks')->cascadeOnUpdate();
            $table->decimal('amount', 12, 2);
            $table->foreignId('causal_id')->constrained('causals')->cascadeOnUpdate();
            $table->text('notes')->nullable();
            $table->boolean('deleted')->default(false);
            $table->timestamps();

            $table->index(['date', 'origin_id', 'destination_id']);
        });
    }

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