<?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::table('dispositivo', function (Blueprint $table) {
            $table->bigInteger('endpoint_id')->unsigned()->nullable();
        });
        Schema::table('dispositivo', function (Blueprint $table) {
            $table->foreign('endpoint_id')->references('id')->on('endpoint')->onDelete('cascade');
        });
        
        Schema::table('print_job', function (Blueprint $table) {
            $table->bigInteger('stampante_id')->unsigned()->nullable();
        });
        Schema::table('print_job', function (Blueprint $table) {
            $table->foreign('stampante_id')->references('id')->on('dispositivo')->where('tipo', \App\Models\Dispositivo::STAMPANTE)->onDelete('cascade');
        });
    }

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