<?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('testi', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('attivita_id')->nullable();
            $table->unsignedBigInteger('user_id')->nullable();
            $table->string('titolo');
            $table->string('descrizione')->nullable();
            $table->text('testo')->nullable();
            $table->string('ambiente')->nullable();
            $table->string('tipo')->nullable();
            $table->boolean('is_attivo')->default(true);
            $table->timestamps();
        });

        Schema::table('testi', function (Blueprint $table) {
            $table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
            $table->foreign('attivita_id')->references('id')->on('attivita')->onDelete('cascade');
        });
    }
};
