<?php

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

// Explicit per-package admin-curated feature awareness. Beyond what WHMCS
// stores in description, admins can hand-write notes (e.g. "premium has SSH
// terminal, budget doesn't") and flip temporary-disable toggles when a
// feature is turned off due to an incident. The AI reads all three columns
// from TicketServiceContext on every draft, so it stops promising features
// that this specific plan doesn't have — or features we've turned off today.
return new class extends Migration {
    public function up(): void
    {
        Schema::table('whmcs_packages', function (Blueprint $t) {
            // Hand-written admin notes — appended to the prompt verbatim.
            // Use this for the "premium has X but budget doesn't" facts the
            // WHMCS description doesn't spell out clearly enough.
            $t->text('admin_notes')->nullable()->after('description');

            // Structured booleans the AI can reason over. Keys are stable
            // (snake_case) so prompts can read them deterministically.
            // Example: {"ssh_access": true, "ssl_included": true,
            //           "mongodb_native": false, "wordpress_managed": true}
            $t->json('feature_flags')->nullable()->after('admin_notes');

            // Subset of feature_flag keys currently turned OFF due to an
            // active incident. AI inserts a "this feature is temporarily
            // unavailable" line when the customer asks about one of these.
            $t->json('temporary_disabled_features')->nullable()->after('feature_flags');

            // Free-text reason that gets appended to the customer-facing
            // "temporarily off" notice (so the AI can say WHY, not just
            // "it's off"). Optional.
            $t->text('temporary_disable_reason')->nullable()->after('temporary_disabled_features');
        });
    }

    public function down(): void
    {
        Schema::table('whmcs_packages', function (Blueprint $t) {
            $t->dropColumn([
                'admin_notes', 'feature_flags',
                'temporary_disabled_features', 'temporary_disable_reason',
            ]);
        });
    }
};
