<?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('ai_voice_recordings', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->unsignedBigInteger('user_id')->comment('작성자 ID');
            $table->string('title', 200)->comment('녹음 제목');
            $table->unsignedBigInteger('interview_template_id')->nullable()->comment('연결된 인터뷰 템플릿 ID');
            $table->string('audio_file_path', 500)->nullable()->comment('GCS 오브젝트 경로');
            $table->string('audio_gcs_uri', 500)->nullable()->comment('GCS URI (gs://...)');
            $table->longText('transcript_text')->nullable()->comment('STT 변환 텍스트');
            $table->longText('analysis_text')->nullable()->comment('Gemini AI 분석 결과');
            $table->string('status', 20)->default('PENDING')->comment('상태: PENDING, PROCESSING, COMPLETED, FAILED');
            $table->unsignedInteger('duration_seconds')->nullable()->comment('녹음 시간(초)');
            $table->timestamp('file_expiry_date')->nullable()->comment('파일 삭제 예정일');
            $table->timestamps();
            $table->softDeletes();

            $table->index('tenant_id');
            $table->index('user_id');
            $table->index('status');
        });
    }

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