<?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('journal_entries', function (Blueprint $table) {
            $table->string('source_type', 30)->nullable()->after('status')
                ->comment('원본 거래 유형: bank_transaction, hometax_invoice, manual');
            $table->string('source_key', 255)->nullable()->after('source_type')
                ->comment('원본 거래 고유키');

            $table->index(['tenant_id', 'source_type', 'source_key'], 'je_source_idx');
        });
    }

    public function down(): void
    {
        Schema::table('journal_entries', function (Blueprint $table) {
            $table->dropIndex('je_source_idx');
            $table->dropColumn(['source_type', 'source_key']);
        });
    }
};
