<?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('expected_expenses', function (Blueprint $table) {
            $table->string('source_type', 50)->nullable()->after('description')->comment('원본 테이블: purchases/withdrawals/bills');
            $table->unsignedBigInteger('source_id')->nullable()->after('source_type')->comment('원본 레코드 ID');

            // 복합 인덱스: 동기화된 레코드 검색용
            $table->index(['source_type', 'source_id'], 'idx_source');
        });
    }

    public function down(): void
    {
        Schema::table('expected_expenses', function (Blueprint $table) {
            $table->dropIndex('idx_source');
            $table->dropColumn(['source_type', 'source_id']);
        });
    }
};
