<?php

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

return new class extends Migration
{
    // 설계용 BOM 템플릿: bom_templates
    public function up(): void
    {
        Schema::create('bom_templates', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('tenant_id')->comment('테넌트ID');
            $table->unsignedBigInteger('model_version_id')->comment('모델버전ID');
            $table->string('name', 100)->default('Main')->comment('템플릿명');
            $table->boolean('is_primary')->default(true)->comment('대표 템플릿 여부');
            $table->text('notes')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->unique(['model_version_id', 'name'], 'uq_bomtpl_mv_name');
            $table->index(['tenant_id', 'model_version_id'], 'idx_bomtpl_tenant_mv');
            $table->index(['tenant_id', 'is_primary'], 'idx_bomtpl_tenant_primary');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('bom_templates');
    }
};
