<?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
    {
        if (Schema::hasTable('level_progressions')) {
            return;
        }

        Schema::create('level_progressions', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('current_level_id')->nullable()->index();
            $table->string('current_level_name', 100);
            $table->unsignedInteger('next_level_id')->nullable()->index();
            $table->string('next_level_name', 100)->nullable();
            $table->unsignedSmallInteger('order_index')->default(0);
            $table->boolean('is_terminal')->default(false);
            $table->boolean('is_active')->default(true);
            $table->text('notes')->nullable();
            $table->timestamps();

            $table->unique('current_level_name', 'uq_level_progressions_current_level_name');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('level_progressions');
    }
};
