<?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('pagamento', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('attivita_id')->unsigned()->nullable();
            $table->bigInteger('ordine_id')->unsigned()->nullable();
            $table->bigInteger('prenotazione_id')->unsigned()->nullable();
            $table->double('importo', 10, 2)->nullable();
            $table->string('causale')->nullable();
            $table->string('stato')->nullable();
            $table->bigInteger('metodo_pagamento_id')->unsigned()->nullable();
            $table->string('note')->nullable();
            $table->json('info')->nullable();
            $table->timestamps();
        });

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

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