<?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('menus')) {
            return;
        }

        Schema::table('menus', function (Blueprint $table) {
            // Enlace del menú (opcional): si es un contenedor, puede quedar vacío
            if (!Schema::hasColumn('menus', 'route_name')) {
                $table->string('route_name', 191)->nullable()->after('nombre');
            }
            if (!Schema::hasColumn('menus', 'url')) {
                $table->string('url', 255)->nullable()->after('route_name');
            }
        });
    }

    public function down(): void
    {
        if (!Schema::hasTable('menus')) {
            return;
        }

        Schema::table('menus', function (Blueprint $table) {
            if (Schema::hasColumn('menus', 'route_name')) {
                $table->dropColumn('route_name');
            }
            if (Schema::hasColumn('menus', 'url')) {
                $table->dropColumn('url');
            }
        });
    }
};
