<?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
    {
        if (Schema::hasTable('typing_job_submissions')) {
            return;
        }

        Schema::create('typing_job_submissions', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->index();
            $table->string('expression', 60);
            $table->string('operator', 1);
            $table->integer('left_operand');
            $table->integer('right_operand');
            $table->integer('correct_answer');
            $table->integer('user_answer');
            $table->decimal('reward_amount', 10, 2)->default(1.00);
            $table->timestamp('submitted_at')->nullable()->index();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        if (!Schema::hasTable('typing_job_submissions')) {
            return;
        }

        Schema::drop('typing_job_submissions');
    }
};
