<?php

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

return new class extends Migration
{
    /**
     * 견적(quotes)에 수주 연결 필드 추가
     * - 견적 → 수주 전환 시 생성된 수주 ID 저장
     * - 전환된 견적 추적용
     */
    public function up(): void
    {
        Schema::table('quotes', function (Blueprint $table) {
            $table->unsignedBigInteger('order_id')->nullable()->after('tenant_id')->comment('전환된 수주 ID');

            $table->index('order_id', 'idx_quotes_order_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('quotes', function (Blueprint $table) {
            $table->dropIndex('idx_quotes_order_id');
            $table->dropColumn('order_id');
        });
    }
};
