<?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::table('expense_accounts', function (Blueprint $table) {
            $table->unsignedBigInteger('journal_entry_id')->nullable()->after('loan_id');
            $table->unsignedBigInteger('journal_entry_line_id')->nullable()->after('journal_entry_id');

            $table->index(['tenant_id', 'journal_entry_id']);
            $table->index(['journal_entry_line_id']);
        });
    }

    public function down(): void
    {
        Schema::table('expense_accounts', function (Blueprint $table) {
            $table->dropIndex(['tenant_id', 'journal_entry_id']);
            $table->dropIndex(['journal_entry_line_id']);
            $table->dropColumn(['journal_entry_id', 'journal_entry_line_id']);
        });
    }
};
