<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('menu_favorites', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->unsignedBigInteger('user_id')->comment('사용자 ID');
            $table->unsignedBigInteger('menu_id')->comment('메뉴 ID');
            $table->integer('sort_order')->default(0)->comment('표시 순서');
            $table->timestamps();

            $table->unique(['tenant_id', 'user_id', 'menu_id']);
            $table->index(['tenant_id', 'user_id', 'sort_order']);

            $table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete();
            $table->foreign('menu_id')->references('id')->on('menus')->cascadeOnDelete();
        });
    }

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