/**
 * Default AI feature catalog. These are the global feature flags surfaced in
 * Settings > AI and (from Phase 3) enforced across CMS modules via
 * `isAiFeatureEnabled(key)`. Seeded into the `__ai_config__` document on first
 * write; admins toggle `enabled` per feature.
 *
 * Keys follow the `ai.features.*` convention so a single shared service governs
 * every module instead of per-module flags.
 */
export const AI_FEATURE_DEFAULTS = [
    {
        key: 'ai.features.seo404Recovery',
        label: '404 Recovery suggestions',
        description: 'Recommend redirect targets for broken URLs that still receive traffic.',
        enabled: true,
        category: 'seo',
        requiredCapabilities: ['text', 'reasoning'],
        approvalRequired: true,
        allowBulkApply: false,
        rolesAllowed: ['ADMIN', 'EDITOR'],
        permissionsRequired: ['ai.use'],
    },
    {
        key: 'ai.features.contentWriting',
        label: 'Content writing suggestions',
        description: 'Draft, rewrite, summarize, and improve content in the editor.',
        enabled: true,
        category: 'content',
        requiredCapabilities: ['text'],
        approvalRequired: true,
        allowBulkApply: false,
        rolesAllowed: ['ADMIN', 'EDITOR'],
        permissionsRequired: ['ai.use'],
    },
    {
        key: 'ai.features.mediaAltText',
        label: 'Auto alt-text for media',
        description: 'Generate descriptive alt text for images on upload or in the SEO drawer.',
        enabled: true,
        category: 'media',
        requiredCapabilities: ['vision'],
        approvalRequired: true,
        allowBulkApply: false,
        rolesAllowed: ['ADMIN', 'EDITOR'],
        permissionsRequired: ['ai.use'],
    },
    {
        key: 'ai.features.seoMetaGeneration',
        label: 'SEO meta generation',
        description: 'Generate SEO titles, meta descriptions, and focus keywords from content.',
        enabled: true,
        category: 'seo',
        requiredCapabilities: ['text'],
        approvalRequired: true,
        allowBulkApply: false,
        rolesAllowed: ['ADMIN', 'EDITOR'],
        permissionsRequired: ['ai.use'],
    },
    {
        key: 'ai.features.redirectChainFlattening',
        label: 'Redirect chain flattening',
        description: 'Suggest direct single-hop redirects to collapse redirect chains.',
        enabled: false,
        category: 'seo',
        requiredCapabilities: ['text', 'reasoning'],
        approvalRequired: true,
        allowBulkApply: false,
        rolesAllowed: ['ADMIN'],
        permissionsRequired: ['ai.use'],
    },
];
/** Deep clone so callers can't mutate the shared default array. */
export function cloneFeatureDefaults() {
    return AI_FEATURE_DEFAULTS.map((f) => ({
        ...f,
        requiredCapabilities: [...f.requiredCapabilities],
        rolesAllowed: [...f.rolesAllowed],
        permissionsRequired: [...f.permissionsRequired],
        fallbackModelIds: f.fallbackModelIds ? [...f.fallbackModelIds] : undefined,
    }));
}
/**
 * Merge stored feature toggles over the current defaults so newly-added features
 * appear automatically and removed/renamed ones drop off, while preserving the
 * admin's `enabled`/routing choices for features that still exist.
 */
export function mergeFeatures(stored) {
    const byKey = new Map((stored ?? []).map((f) => [f.key, f]));
    return cloneFeatureDefaults().map((def) => {
        const prev = byKey.get(def.key);
        if (!prev)
            return def;
        return {
            ...def,
            enabled: typeof prev.enabled === 'boolean' ? prev.enabled : def.enabled,
            providerId: prev.providerId ?? def.providerId,
            modelId: prev.modelId ?? def.modelId,
            fallbackModelIds: prev.fallbackModelIds ?? def.fallbackModelIds,
            maxMonthlyTokens: prev.maxMonthlyTokens ?? def.maxMonthlyTokens,
            maxRequestsPerDay: prev.maxRequestsPerDay ?? def.maxRequestsPerDay,
        };
    });
}
//# sourceMappingURL=feature-defaults.js.map