<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('ocr_question_results', function (Blueprint $table) {
            // 添加题目生成相关字段
            $table->string('generation_status', 50)->nullable()->after('score_confidence')->comment('生成状态：pending, generating, completed, failed');
            $table->string('generation_task_id', 100)->nullable()->after('generation_status')->comment('生成任务ID');
            $table->text('generation_error')->nullable()->after('generation_task_id')->comment('生成错误信息');

            // 创建索引
            $table->index('generation_status', 'idx_ocr_question_results_gen_status');
            $table->index('generation_task_id', 'idx_ocr_question_results_gen_task_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('ocr_question_results', function (Blueprint $table) {
            // 删除索引
            $table->dropIndex('idx_ocr_question_results_gen_status');
            $table->dropIndex('idx_ocr_question_results_gen_task_id');

            // 删除字段
            $table->dropColumn('generation_status');
            $table->dropColumn('generation_task_id');
            $table->dropColumn('generation_error');
        });
    }
};
