<?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('monitor_has_contenuto', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('monitor_id')->unsigned()->nullable();
            $table->boolean('is_bacheca')->default(false);
            $table->bigInteger('cucina_id')->unsigned()->nullable();
            $table->bigInteger('contenuto_bacheca_id')->unsigned()->nullable();
            $table->timestamps();
        });
        Schema::table('monitor_has_contenuto', function (Blueprint $table) {
            $table->foreign('monitor_id')->references('id')->on('dispositivo')->onDelete('set null');
            $table->foreign('cucina_id')->references('id')->on('cucina')->onDelete('set null');
            $table->foreign('contenuto_bacheca_id')->references('id')->on('contenuto_bacheca')->onDelete('set null');
        });
    }

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