// engine/plugins/extensions/template-extension.ts — Template registration (SPEC-085 AC-07)
/** Registry of plugin templates keyed by `{pluginId}:{templateName}` */
const templateRegistry = new Map();
function templateKey(pluginId, templateName) {
    return `${pluginId}:${templateName}`;
}
/**
 * Registers templates from a plugin.
 */
export function registerPluginTemplates(pluginId, templates) {
    const registered = [];
    for (const template of templates) {
        const key = templateKey(pluginId, template.name);
        if (templateRegistry.has(key)) {
            throw new Error(`Template "${template.name}" already registered for plugin "${pluginId}"`);
        }
        templateRegistry.set(key, { pluginId, definition: template });
        registered.push(key);
    }
    return registered;
}
/**
 * Unregisters all templates belonging to a plugin.
 */
export function unregisterPluginTemplates(pluginId) {
    const removed = [];
    for (const [key, entry] of templateRegistry) {
        if (entry.pluginId === pluginId) {
            templateRegistry.delete(key);
            removed.push(key);
        }
    }
    return removed;
}
/**
 * Returns all registered plugin templates, optionally filtered by domain.
 */
export function getPluginTemplates(domain) {
    const results = [];
    for (const entry of templateRegistry.values()) {
        if (!domain || entry.definition.domain === domain) {
            results.push({ pluginId: entry.pluginId, template: entry.definition });
        }
    }
    return results;
}
/**
 * Returns the count of templates registered for a specific plugin.
 */
export function getPluginTemplateCount(pluginId) {
    let count = 0;
    for (const entry of templateRegistry.values()) {
        if (entry.pluginId === pluginId) {
            count++;
        }
    }
    return count;
}
/**
 * Clears all template registrations (for testing).
 */
export function clearTemplateRegistry() {
    templateRegistry.clear();
}
//# sourceMappingURL=template-extension.js.map