<?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('ocr_question_results', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('ocr_record_id')->index();
            $table->foreign('ocr_record_id')->references('id')->on('ocr_records')->onDelete('cascade');

            // 题目基本信息
            $table->integer('question_number');
            $table->string('kp_code', 50)->nullable()->index();
            $table->text('skill_ids')->nullable();

            // 批改标记识别
            $table->string('score_area_text', 100)->nullable();
            $table->text('score_area_bbox')->nullable();
            $table->integer('score_value')->nullable();
            $table->decimal('score_confidence', 5, 4)->nullable();

            // 老师批改标记
            $table->string('mark_detected', 10)->nullable();
            $table->decimal('mark_confidence', 5, 4)->nullable();

            // 学生作答识别
            $table->text('student_answer')->nullable();
            $table->text('student_answer_bbox')->nullable();
            $table->decimal('answer_confidence', 5, 4)->nullable();
            $table->string('answer_area_crop_path', 500)->nullable();

            // 题目内容识别
            $table->text('question_text')->nullable();
            $table->text('question_bbox')->nullable();
        });
    }

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