<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('menu_items', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('parent_id')->nullable();
            $table->unsignedBigInteger('menu_id');
            $table->unsignedBigInteger('page_id')->nullable();
            $table->string('target', 20)->nullable();
            $table->unsignedInteger('position')->nullable();
            $table->boolean('active')->default(true);
            $table->unsignedBigInteger('backend_user_id')->nullable();
            $table->nullableTimestamps();

            $table->foreign('parent_id')->references('id')
                ->on('menu_items')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('menu_id')->references('id')
                ->on('menus')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('page_id')->references('id')
                ->on('pages')->onDelete('CASCADE')->onUpdate('CASCADE');

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('menu_items');
    }
};
