<?php
declare(strict_types=1);

namespace Ekesto\CacheAutopilot;

use Ekesto\CacheInvalidator\Core\FeatureFlags;

/**
 * Central runtime entitlement check for premium implementation wiring.
 *
 * Build availability remains owned by FeatureFlags::isPremium(). This helper
 * adds the runtime licensing entitlement decision only when the licensing accessor
 * exists, while allowing private Pro builds to keep using packaged Pro
 * implementation classes.
 */
final class ProEntitlement
{
    /**
     * Return whether Pro runtime features may be registered for this request.
     *
     * @return bool
     */
    public static function canUseProFeatures(): bool
    {
        $accessor = 'ekesto_ca_' . 'fs';

        if (!function_exists($accessor)) {
            return FeatureFlags::isPremium();
        }

        $licensing = $accessor();
        if (!is_object($licensing)) {
            return false;
        }

        if (!method_exists($licensing, 'can_use_premium_code__premium_only')) {
            return false;
        }

        return (bool) $licensing->can_use_premium_code__premium_only();
    }
}
