import { TrendAnalyzer } from './trend-analyzer.js';
import { GapAnalyzer } from './gap-analyzer.js';
import { SynergyDetector } from './synergy-detector.js';
import { TemplateExtractor } from './template-extractor.js';
import { InsightGenerator } from './insight-generator.js';
import { BaseResearchEngine } from '@timmeck/brain-core';
export class ResearchEngine extends BaseResearchEngine {
    config;
    errorRepo;
    solutionRepo;
    projectRepo;
    codeModuleRepo;
    synapseRepo;
    insightRepo;
    synapseManager;
    trendAnalyzer;
    gapAnalyzer;
    synergyDetector;
    templateExtractor;
    insightGenerator;
    constructor(config, errorRepo, solutionRepo, projectRepo, codeModuleRepo, synapseRepo, insightRepo, synapseManager) {
        super(config);
        this.config = config;
        this.errorRepo = errorRepo;
        this.solutionRepo = solutionRepo;
        this.projectRepo = projectRepo;
        this.codeModuleRepo = codeModuleRepo;
        this.synapseRepo = synapseRepo;
        this.insightRepo = insightRepo;
        this.synapseManager = synapseManager;
        this.trendAnalyzer = new TrendAnalyzer(errorRepo, solutionRepo, projectRepo, insightRepo, config);
        this.gapAnalyzer = new GapAnalyzer(errorRepo, solutionRepo, synapseRepo, projectRepo, insightRepo, config);
        this.synergyDetector = new SynergyDetector(synapseRepo, codeModuleRepo, solutionRepo, errorRepo, projectRepo, insightRepo, config);
        this.templateExtractor = new TemplateExtractor(codeModuleRepo, projectRepo, insightRepo, config);
        this.insightGenerator = new InsightGenerator(projectRepo, errorRepo, solutionRepo, codeModuleRepo, insightRepo, config);
    }
    runCycle() {
        const start = Date.now();
        this.logger.info('Research cycle starting');
        const result = {
            insightsGenerated: 0,
            patternsFound: 0,
            correlationsFound: 0,
            duration: 0,
        };
        // Phase 1: Trend analysis
        const trends = this.trendAnalyzer.analyze();
        result.patternsFound += trends;
        result.insightsGenerated += trends;
        // Phase 2: Gap analysis
        const gaps = this.gapAnalyzer.analyze();
        result.insightsGenerated += gaps;
        // Phase 3: Synergy detection
        const synergies = this.synergyDetector.detect();
        result.correlationsFound += synergies;
        result.insightsGenerated += synergies;
        // Phase 4: Template extraction
        const templates = this.templateExtractor.extract();
        result.patternsFound += templates;
        result.insightsGenerated += templates;
        // Phase 5: Insight generation
        const generated = this.insightGenerator.generate();
        result.insightsGenerated += generated;
        // Phase 6: Insight prioritization (expire old insights)
        const expired = this.insightRepo.expire();
        if (expired > 0) {
            this.logger.info(`Expired ${expired} outdated insights`);
        }
        // Phase 7: Synapse maintenance
        const decay = this.synapseManager.runDecay();
        this.logger.debug(`Synapse maintenance: ${decay.decayed} decayed, ${decay.pruned} pruned`);
        result.duration = Date.now() - start;
        this.logger.info(`Research cycle complete: ${result.insightsGenerated} insights, ${result.patternsFound} patterns, ${result.correlationsFound} correlations (${result.duration}ms)`);
        return result;
    }
}
//# sourceMappingURL=research-engine.js.map