<?php

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

return new class extends Migration
{
    /**
     * Add rich media support to exam questions:
     *   - question_media_path  : uploaded file (image/pdf/video/presentation)
     *   - question_media_type  : type of the uploaded file
     *   - question_media_name  : original filename
     *   - question_media_size  : file size in bytes
     *   - upload_required      : whether learner must upload a file to answer
     *   - upload_label         : instruction shown to learner for the upload
     */
    public function up(): void
    {
        Schema::table('self_paced_exam_questions', function (Blueprint $table) {
            $table->string('question_media_path')->nullable()->after('explanation');
            $table->enum('question_media_type', ['image', 'pdf', 'video', 'presentation', 'excel'])->nullable()->after('question_media_path');
            $table->string('question_media_name', 191)->nullable()->after('question_media_type');
            $table->unsignedBigInteger('question_media_size')->default(0)->after('question_media_name');
            $table->boolean('upload_required')->default(false)->after('question_media_size');
            $table->string('upload_label', 500)->nullable()->after('upload_required');
        });
    }

    public function down(): void
    {
        Schema::table('self_paced_exam_questions', function (Blueprint $table) {
            $table->dropColumn([
                'question_media_path',
                'question_media_type',
                'question_media_name',
                'question_media_size',
                'upload_required',
                'upload_label',
            ]);
        });
    }
};
