<?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('categoria_contabile', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('attivita_id')->unsigned()->nullable();
            $table->string('nome')->unique();
            $table->string('descrizione')->nullable();
            $table->boolean('is_attiva')->default(true);
            $table->string('colore')->nullable();
            $table->json('info')->nullable();
            $table->timestamps();
        });

        Schema::table('prima_nota', function (Blueprint $table) {
            $table->foreign('categoria_contabile_id')->references('id')->on('categoria_contabile')->onDelete('cascade');
        });
    }

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