<?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('prima_nota', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('attivita_id')->unsigned()->nullable();
            $table->bigInteger('pagamento_id')->unsigned()->nullable();
            $table->bigInteger('ordine_id')->unsigned()->nullable();
            $table->bigInteger('prenotazione_id')->unsigned()->nullable();
            $table->bigInteger('evento_id')->unsigned()->nullable();
            $table->bigInteger('fornitore_id')->unsigned()->nullable();
            $table->bigInteger('categoria_contabile_id')->unsigned()->nullable();
            $table->string('riferimento')->nullable();
            $table->double('importo', 10, 2)->nullable();
            $table->string('tipo_movimento')->nullable();
            $table->string('causale')->nullable();
            $table->string('stato')->nullable();
            $table->timestamps();
        });

        Schema::table('prima_nota', function (Blueprint $table) {
            $table->foreign('attivita_id')->references('id')->on('attivita')->onDelete('cascade');
            $table->foreign('pagamento_id')->references('id')->on('pagamento')->onDelete('cascade');
            $table->foreign('ordine_id')->references('id')->on('ordine')->onDelete('cascade');
            $table->foreign('prenotazione_id')->references('id')->on('prenotazione')->onDelete('cascade');
            $table->foreign('evento_id')->references('id')->on('evento')->onDelete('cascade');
            $table->foreign('fornitore_id')->references('id')->on('fornitore')->onDelete('cascade');
        });
    }

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