<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('quotes', function (Blueprint $table) {
            $table->string('quote_type', 20)
                ->default('manufacturing')
                ->after('tenant_id')
                ->comment('견적 유형: manufacturing(제조), construction(시공)');

            $table->index('quote_type', 'idx_quotes_quote_type');
        });

        // 기존 데이터: site_briefing_id가 있으면 construction으로 설정
        DB::table('quotes')
            ->whereNotNull('site_briefing_id')
            ->update(['quote_type' => 'construction']);
    }

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