<?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
    {
        Schema::table('interview_questions', function (Blueprint $table) {
            if (!Schema::hasColumn('interview_questions', 'option_a')) {
                $table->text('option_a')->after('question');
            }
            if (!Schema::hasColumn('interview_questions', 'option_b')) {
                $table->text('option_b')->after('option_a');
            }
            if (!Schema::hasColumn('interview_questions', 'option_c')) {
                $table->text('option_c')->after('option_b');
            }
            if (!Schema::hasColumn('interview_questions', 'option_d')) {
                $table->text('option_d')->after('option_c');
            }
            if (!Schema::hasColumn('interview_questions', 'correct_answer')) {
                $table->char('correct_answer', 1)->comment('a, b, c or d')->after('option_d');
            }
            if (!Schema::hasColumn('interview_questions', 'explanation')) {
                $table->text('explanation')->nullable()->after('correct_answer');
            }
            if (!Schema::hasColumn('interview_questions', 'difficulty')) {
                $table->unsignedInteger('difficulty')->default(1)->comment('1-5')->after('explanation');
            }
        });
    }

    public function down(): void
    {
        Schema::table('interview_questions', function (Blueprint $table) {
            $table->dropColumnIfExists(['option_a', 'option_b', 'option_c', 'option_d', 'correct_answer', 'explanation', 'difficulty']);
        });
    }
};
