<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * Menu dinamis (RPD §12.2 menu). Hierarki parent-child, label/link/icon/urutan.
     * `section` memetakan menu ke kelompok tampilan sidebar (mis. "Utama", "Iklan").
     */
    public function up(): void
    {
        Schema::create('menus', function (Blueprint $table) {
            $table->id();
            $table->string('label', 100);
            $table->string('route', 120)->nullable();   // named route (mis. campaigns.index)
            $table->string('link', 200)->nullable();     // URL/external absolut bila tidak pakai named route
            $table->string('icon', 60)->nullable();      // nama Lucide (string)
            $table->string('section', 60)->default('Utama'); // kelompok di sidebar
            $table->foreignId('menu_type_id')->constrained()->cascadeOnDelete();
            $table->foreignId('parent_id')->nullable()->constrained('menus')->cascadeOnDelete();
            $table->unsignedSmallInteger('sort_order')->default(0);
            $table->boolean('status')->default(true);
            $table->timestamps();

            $table->index(['menu_type_id', 'status', 'sort_order']);
        });
    }

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