<?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('endpoint', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('attivita_id')->unsigned()->nullable();
            $table->string('label')->nullable();
            $table->string('descrizione')->nullable();
            $table->string('ubicazione')->nullable();
            $table->string('url')->nullable();
            $table->bigInteger('user_id')->unsigned()->nullable();
            $table->string('token')->nullable();
            $table->string('product_key')->unique()->nullable()->length(25);
            $table->string('secret')->nullable();
            $table->string('status')->nullable();
            $table->string('type')->nullable();
            $table->string('version')->nullable();
            $table->bigInteger('licenza_id')->unsigned()->nullable();
            $table->json('info')->nullable();
            $table->timestamp('last_heartbeat')->nullable();
            $table->timestamp('last_activity')->nullable();
            $table->timestamps();
        });
        Schema::table('endpoint', function (Blueprint $table) {
            $table->foreign('attivita_id')->references('id')->on('attivita')->onDelete('cascade');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            // $table->foreign('licenza_id')->references('id')->on('licenza')->onDelete('cascade');
        });
    }

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