<?php

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

return new class extends Migration
{
    /**
     * 결재(approvals) 테이블에 연결 대상(linkable) 컬럼 추가
     * - Document 시스템과 Approval 시스템을 브릿지하기 위한 다형성 관계
     */
    public function up(): void
    {
        Schema::table('approvals', function (Blueprint $table) {
            $table->string('linkable_type')->nullable()->after('attachments')->comment('연결 대상 모델 (예: App\\Models\\Documents\\Document)');
            $table->unsignedBigInteger('linkable_id')->nullable()->after('linkable_type')->comment('연결 대상 ID');
            $table->index(['linkable_type', 'linkable_id'], 'idx_linkable');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('approvals', function (Blueprint $table) {
            $table->dropIndex('idx_linkable');
            $table->dropColumn(['linkable_type', 'linkable_id']);
        });
    }
};
