<?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_attachments', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->unsignedBigInteger('interview_project_id')->comment('인터뷰 프로젝트 ID');
            $table->enum('file_type', ['excel_template', 'pdf_quote', 'sample_bom', 'price_list', 'photo', 'voice', 'other'])
                ->default('other')->comment('파일 유형');
            $table->string('file_name', 255)->comment('파일명');
            $table->string('file_path', 500)->comment('저장 경로');
            $table->unsignedInteger('file_size')->default(0)->comment('파일 크기 (bytes)');
            $table->string('mime_type', 100)->nullable()->comment('MIME 타입');
            $table->json('ai_analysis')->nullable()->comment('AI 분석 결과');
            $table->enum('ai_analysis_status', ['pending', 'processing', 'completed', 'failed'])
                ->default('pending')->comment('AI 분석 상태');
            $table->text('description')->nullable()->comment('설명');
            $table->unsignedBigInteger('created_by')->nullable()->comment('등록자');
            $table->timestamps();

            $table->index('tenant_id', 'idx_interview_attachments_tenant');
            $table->index('interview_project_id', 'idx_interview_attachments_project');
            $table->index('file_type', 'idx_interview_attachments_type');
        });
    }

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