<?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->decimal('score_value', 5, 2)->nullable()->after('student_answer')->comment('得分值');
            $table->boolean('mark_detected')->nullable()->after('score_value')->comment('是否检测到评分标记');
            $table->decimal('score_confidence', 5, 4)->nullable()->after('mark_detected')->comment('评分置信度');

            // 创建索引
            $table->index(['score_value', 'mark_detected'], 'idx_ocr_question_results_score');
        });
    }

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

            // 删除字段
            $table->dropColumn('score_value');
            $table->dropColumn('mark_detected');
            $table->dropColumn('score_confidence');
        });
    }
};
