<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('question_bank_questions', function (Blueprint $table) {
            $table->foreignId('parent_question_id')->nullable()->after('section_id')->constrained('question_bank_questions')->onDelete('cascade');
            $table->string('condition_value')->nullable()->after('parent_question_id');
            $table->integer('display_order')->default(0)->after('condition_value');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('question_bank_questions', function (Blueprint $table) {
            $table->dropForeign(['parent_question_id']);
            $table->dropColumn(['parent_question_id', 'condition_value', 'display_order']);
        });
    }
};
