<?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('allergene', function (Blueprint $table) {
            $table->id();
            $table->string('nome');
            $table->string('descrizione')->nullable();
            $table->boolean('disponibile')->default(true);
            $table->longText('icona')->nullable();
            $table->string('colore')->nullable();
            $table->timestamps();
        });

        Schema::create('piatto_allergene', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('piatto_id')->unsigned();
            $table->bigInteger('allergene_id')->unsigned();
            $table->timestamps();
        });

        Schema::table('piatto_allergene', function (Blueprint $table) {
            $table->foreign('piatto_id')->references('id')->on('piatto')->onDelete('cascade');
            $table->foreign('allergene_id')->references('id')->on('allergene')->onDelete('cascade');
        });
    }

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