<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('gruppo_individuo', function (Blueprint $table) {
            $table->dropForeign(['ruolo_id']);
            $table->dropColumn('ruolo_id');
        });

        Schema::table('gruppo_individuo', function (Blueprint $table) {
            $table->json('ruolo_ids')->nullable()->after('individuo_id');
        });
    }

    public function down(): void
    {
        Schema::table('gruppo_individuo', function (Blueprint $table) {
            $table->dropColumn('ruolo_ids');
        });

        Schema::table('gruppo_individuo', function (Blueprint $table) {
            $table->unsignedBigInteger('ruolo_id')->nullable()->after('individuo_id');
            $table->foreign('ruolo_id')->references('id')->on('ruoli')->onDelete('set null');
        });
    }
};