<?php

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

/**
 * Adds `autoload_paths` JSON to installed_plugins so PluginManager can
 * persist PSR-4 prefix=>path pairs declared in plugin manifests. Loaded at
 * boot by PluginLoader and used for hook/route handler class resolution.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('installed_plugins', function (Blueprint $table) {
            if (! Schema::hasColumn('installed_plugins', 'autoload_paths')) {
                $table->json('autoload_paths')->nullable()->after('manifest');
            }
        });
    }

    public function down(): void
    {
        Schema::table('installed_plugins', function (Blueprint $table) {
            if (Schema::hasColumn('installed_plugins', 'autoload_paths')) {
                $table->dropColumn('autoload_paths');
            }
        });
    }
};
