<?php

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

return new class extends Migration
{
    /**
     * Add rich-text question body and multi-answer support to exam questions.
     *
     * question_text_html     — rich HTML version of the question (from Quill editor)
     * allow_multiple_answers — when true, learner selects multiple options
     * correct_answers_json   — JSON array of correct letters e.g. ["A","C"]
     *                          used when allow_multiple_answers = true
     *                          (correct_answer column kept for single-answer backward compat)
     */
    public function up(): void
    {
        Schema::table('self_paced_exam_questions', function (Blueprint $table) {
            $table->longText('question_text_html')->nullable()->after('question_text')
                  ->comment('Rich HTML version of the question text (Quill output)');
            $table->boolean('allow_multiple_answers')->default(false)->after('correct_answer');
            $table->json('correct_answers_json')->nullable()->after('allow_multiple_answers')
                  ->comment('Array of correct option letters for multi-answer questions e.g. ["A","C"]');
        });
    }

    public function down(): void
    {
        Schema::table('self_paced_exam_questions', function (Blueprint $table) {
            $table->dropColumn(['question_text_html', 'allow_multiple_answers', 'correct_answers_json']);
        });
    }
};
