<?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
    {
        // 결재라인에 user_id 추가
        Schema::table('document_template_approval_lines', function (Blueprint $table) {
            $table->unsignedBigInteger('user_id')->nullable()->after('role')
                ->comment('담당자 ID (작성 단계는 null)');
        });

        // 문서양식에 연결 필드 추가
        Schema::table('document_templates', function (Blueprint $table) {
            $table->json('linked_item_ids')->nullable()->after('is_active')
                ->comment('수입검사 시 연결된 품목 ID 배열');
            $table->unsignedBigInteger('linked_process_id')->nullable()->after('linked_item_ids')
                ->comment('품질검사 시 연결된 공정 ID');
        });
    }

    public function down(): void
    {
        Schema::table('document_template_approval_lines', function (Blueprint $table) {
            $table->dropColumn('user_id');
        });

        Schema::table('document_templates', function (Blueprint $table) {
            $table->dropColumn(['linked_item_ids', 'linked_process_id']);
        });
    }
};
