<?php

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

return new class extends Migration
{
    /**
     * Stores files uploaded by learners in response to exam questions
     * that have upload_required = true.
     */
    public function up(): void
    {
        Schema::create('self_paced_exam_uploads', function (Blueprint $table) {
            $table->id();
            $table->foreignId('attempt_id')->constrained('self_paced_exam_attempts')->cascadeOnDelete();
            $table->foreignId('question_id')->constrained('self_paced_exam_questions')->cascadeOnDelete();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->string('file_path');
            $table->string('file_name', 191);
            $table->unsignedBigInteger('file_size')->default(0);
            $table->string('mime_type', 100)->nullable();
            $table->timestamps();

            $table->index(['attempt_id', 'question_id']);
        });
    }

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