import { getActuateConfig } from '../config/runtime.js';
const TIER_ORDER = {
    starter: 0,
    pro: 1,
    enterprise: 2,
};
const FEATURE_MIN_TIER = {
    'seo.inlineApply': 'pro',
    'seo.contentBrief': 'pro',
    'seo.contentResearch': 'pro',
    'seo.batchContentBriefs': 'pro',
};
const PRO_FEATURES = [
    'seo.inlineApply',
    'seo.contentBrief',
    'seo.contentResearch',
    'seo.batchContentBriefs',
];
function parsePlanTier(raw) {
    if (raw === 'starter' || raw === 'pro' || raw === 'enterprise')
        return raw;
    return null;
}
/** Resolve the active plan tier (env override, then config, then `pro`). */
export function getPlanTier() {
    const fromEnv = parsePlanTier(process.env.CMS_PLAN_TIER?.trim());
    if (fromEnv)
        return fromEnv;
    const fromConfig = parsePlanTier(getActuateConfig()?.plan?.tier);
    if (fromConfig)
        return fromConfig;
    return 'pro';
}
export function getPlanUpgradeUrl() {
    const url = getActuateConfig()?.plan?.upgradeUrl?.trim();
    return url || undefined;
}
export function listPlanFeatures(tier = getPlanTier()) {
    if (tier === 'starter')
        return [];
    return [...PRO_FEATURES];
}
export function hasPlanFeature(feature, tier = getPlanTier()) {
    const required = FEATURE_MIN_TIER[feature];
    return TIER_ORDER[tier] >= TIER_ORDER[required];
}
export function assertPlanFeature(feature) {
    if (hasPlanFeature(feature))
        return null;
    const requiredTier = FEATURE_MIN_TIER[feature];
    return {
        feature,
        requiredTier,
        message: `This feature requires the ${requiredTier} plan.`,
    };
}
export function planFeatureLabel(feature) {
    switch (feature) {
        case 'seo.inlineApply':
            return 'SEO inline apply';
        case 'seo.contentBrief':
            return 'SEO content briefs';
        case 'seo.contentResearch':
            return 'SEO topic research';
        case 'seo.batchContentBriefs':
            return 'SEO batch content briefs';
        default: {
            const _exhaustive = feature;
            return _exhaustive;
        }
    }
}
//# sourceMappingURL=features.js.map