"use strict";
/**
 * FAF Integration Registry
 *
 * Central registry for all approved FAF integrations
 * Orchestrates detection and context generation
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.n8nDetector = exports.viteDetector = exports.typescriptDetector = exports.svelteDetector = exports.nextDetector = exports.reactDetector = exports.integrationRegistry = exports.FafIntegrationRegistry = void 0;
const react_js_1 = require("./detectors/react.js");
Object.defineProperty(exports, "reactDetector", { enumerable: true, get: function () { return react_js_1.reactDetector; } });
const next_js_1 = require("./detectors/next.js");
Object.defineProperty(exports, "nextDetector", { enumerable: true, get: function () { return next_js_1.nextDetector; } });
const svelte_js_1 = require("./detectors/svelte.js");
Object.defineProperty(exports, "svelteDetector", { enumerable: true, get: function () { return svelte_js_1.svelteDetector; } });
const typescript_js_1 = require("./detectors/typescript.js");
Object.defineProperty(exports, "typescriptDetector", { enumerable: true, get: function () { return typescript_js_1.typescriptDetector; } });
const vite_js_1 = require("./detectors/vite.js");
Object.defineProperty(exports, "viteDetector", { enumerable: true, get: function () { return vite_js_1.viteDetector; } });
const n8n_js_1 = require("./detectors/n8n.js");
Object.defineProperty(exports, "n8nDetector", { enumerable: true, get: function () { return n8n_js_1.n8nDetector; } });
/**
 * FAF Integration Registry
 *
 * Championship standard: Only integrations with 85+ quality score
 */
class FafIntegrationRegistry {
    integrations;
    constructor() {
        this.integrations = new Map();
        // Phase 1: Core integrations (85+ quality score)
        this.register(react_js_1.reactDetector);
        this.register(next_js_1.nextDetector);
        this.register(svelte_js_1.svelteDetector);
        this.register(typescript_js_1.typescriptDetector);
        this.register(vite_js_1.viteDetector);
        this.register(n8n_js_1.n8nDetector);
    }
    /**
     * Register a new integration
     */
    register(detector) {
        this.integrations.set(detector.name, detector);
    }
    /**
     * Get integration by name
     */
    get(name) {
        return this.integrations.get(name);
    }
    /**
     * Detect all integrations present in a project
     */
    async detectAll(projectPath) {
        const detected = [];
        for (const detector of this.integrations.values()) {
            try {
                const isPresent = await detector.detect(projectPath);
                if (isPresent) {
                    detected.push(detector);
                }
            }
            catch (error) {
                console.error(`Error detecting ${detector.name}:`, error);
            }
        }
        return detected;
    }
    /**
     * Generate combined .faf context from all detected integrations
     */
    async generateContext(projectPath) {
        const detected = await this.detectAll(projectPath);
        // Merge contexts from all detected integrations
        let combinedContext = {
            stack: {},
            project: {},
            integration: {
                detected_frameworks: [],
                mcp_servers: [],
                recommended_tools: [],
            },
        };
        for (const detector of detected) {
            try {
                const context = await detector.generateContext(projectPath);
                // Merge stack information
                if (context.stack) {
                    combinedContext.stack = {
                        ...combinedContext.stack,
                        ...context.stack,
                    };
                }
                // Merge project information
                if (context.project) {
                    combinedContext.project = {
                        ...combinedContext.project,
                        ...context.project,
                    };
                }
                // Accumulate integration information
                if (context.integration) {
                    combinedContext.integration.detected_frameworks.push(detector.name);
                    combinedContext.integration.mcp_servers.push(...(context.integration.mcp_servers || []));
                    combinedContext.integration.recommended_tools.push(...(context.integration.recommended_tools || []));
                }
            }
            catch (error) {
                console.error(`Error generating context for ${detector.name}:`, error);
            }
        }
        // Add integration summary
        combinedContext.integration.summary = this.generateSummary(detected);
        return combinedContext;
    }
    /**
     * Generate human-readable summary of detected integrations
     */
    generateSummary(detected) {
        if (detected.length === 0) {
            return 'No FAF integrations detected';
        }
        const tiers = detected.map((d) => `${d.displayName} (${d.tier})`);
        const frameworks = detected.map((d) => d.displayName).join(', ');
        return `Fully integrated with: ${frameworks} | ${detected.length} championship-grade integration${detected.length > 1 ? 's' : ''}`;
    }
    /**
     * Get all integration names
     */
    list() {
        return Array.from(this.integrations.keys());
    }
    /**
     * Get integration statistics
     */
    getStats() {
        const stats = {
            total: this.integrations.size,
            byTier: {},
            totalWeeklyAdoption: 0,
        };
        for (const detector of this.integrations.values()) {
            // Count by tier
            stats.byTier[detector.tier] = (stats.byTier[detector.tier] || 0) + 1;
            // Sum weekly adoption
            stats.totalWeeklyAdoption += detector.weeklyAdoption;
        }
        return stats;
    }
}
exports.FafIntegrationRegistry = FafIntegrationRegistry;
// Export singleton instance
exports.integrationRegistry = new FafIntegrationRegistry();
//# sourceMappingURL=registry.js.map