<?php

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

return new class extends Migration
{
    /**
     * Per-business module entitlements: which gateable modules (e.g. VetClinic,
     * ClinicSite) this tenant may see/reach. Stored as a JSON list of module
     * names. NULL = fully entitled (fail-open); [] = none. Owned by the
     * SaasSwitcher module (loaded via SaasSwitcherServiceProvider::loadMigrationsFrom),
     * so no core migration is added. Idempotent.
     */
    public function up()
    {
        if (! Schema::hasColumn('business', 'module_entitlements')) {
            Schema::table('business', function (Blueprint $table) {
                $table->text('module_entitlements')
                    ->after('enabled_modules')
                    ->nullable();
            });
        }
    }

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