<?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_records', function (Blueprint $table) {
            $table->id();
            $table->string('exam_id', 100)->nullable();
            $table->string('student_id', 100);

            // 图像信息
            $table->string('image_path')->nullable();
            $table->string('image_filename')->nullable();
            $table->integer('image_size')->nullable();
            $table->integer('image_width')->nullable();
            $table->integer('image_height')->nullable();

            // QR码数据
            $table->text('qr_code_data')->nullable();

            // 处理状态
            $table->string('status', 50)->default('pending');
            $table->text('error_message')->nullable();

            // 识别统计
            $table->integer('total_questions')->default(0);
            $table->integer('processed_questions')->default(0);
            $table->decimal('confidence_avg', 5, 4)->nullable();

            // 时间戳
            $table->timestamp('processed_at')->nullable();
            $table->timestamps();

            // 索引
            $table->index('exam_id');
            $table->index('student_id');
            $table->index('status');
        });
    }

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