<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // MySQL: Ubah enum difficulty menjadi nullable, default NULL
        DB::statement("ALTER TABLE questions MODIFY difficulty ENUM('mudah','sedang','sulit') NULL DEFAULT NULL");
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        // Kembalikan ke NOT NULL dengan default sedang
        // Set nilai NULL menjadi 'sedang' dulu sebelum NOT NULL
        DB::statement("UPDATE questions SET difficulty = 'sedang' WHERE difficulty IS NULL");
        DB::statement("ALTER TABLE questions MODIFY difficulty ENUM('mudah','sedang','sulit') NOT NULL DEFAULT 'sedang'");
    }
};
