<?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
    {
        Schema::create('interview_knowledge', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->unsignedBigInteger('interview_project_id')->comment('인터뷰 프로젝트 ID');
            $table->enum('domain', [
                'product_classification', 'bom_structure', 'dimension_formula',
                'component_config', 'pricing_structure', 'quantity_formula',
                'conditional_logic', 'quote_format',
            ])->comment('도메인 영역');
            $table->enum('knowledge_type', ['fact', 'rule', 'formula', 'mapping', 'range', 'table'])
                ->comment('지식 유형');
            $table->string('title', 300)->comment('제목');
            $table->json('content')->comment('구조화된 지식 데이터');
            $table->enum('source_type', ['interview_answer', 'voice_recording', 'document', 'manual'])
                ->comment('출처 유형');
            $table->unsignedBigInteger('source_id')->nullable()->comment('출처 레코드 ID');
            $table->decimal('confidence', 3, 2)->default(0.00)->comment('AI 신뢰도 (0.00~1.00)');
            $table->boolean('is_verified')->default(false)->comment('사용자 검증 여부');
            $table->unsignedBigInteger('verified_by')->nullable()->comment('검증자');
            $table->timestamp('verified_at')->nullable()->comment('검증 일시');
            $table->unsignedBigInteger('created_by')->nullable()->comment('등록자');
            $table->timestamps();
            $table->softDeletes();

            $table->index('tenant_id', 'idx_interview_knowledge_tenant');
            $table->index('interview_project_id', 'idx_interview_knowledge_project');
            $table->index('domain', 'idx_interview_knowledge_domain');
            $table->index('is_verified', 'idx_interview_knowledge_verified');
        });
    }

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