"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildProfile = buildProfile;
exports.profileToString = profileToString;
function buildProfile(developerId, patterns, outcomesMap) {
    const languages = {};
    const frameworks = {};
    const projectTypes = new Set();
    const categoryCount = {};
    let totalSignals = 0;
    let totalPositive = 0;
    let totalUsage = 0;
    let totalSuccess = 0;
    let totalFailures = 0;
    for (const p of patterns) {
        for (const c of p.conditions) {
            if (c.type === 'language') {
                languages[c.value] = (languages[c.value] || 0) + 1;
            }
            else if (c.type === 'framework') {
                frameworks[c.value] = (frameworks[c.value] || 0) + 1;
            }
            else if (c.type === 'file_type') {
                projectTypes.add(c.value);
            }
        }
        if (p.meta.language && p.meta.language !== 'unknown') {
            languages[p.meta.language] = (languages[p.meta.language] || 0) + 1;
        }
        categoryCount[p.category] = (categoryCount[p.category] || 0) + 1;
        totalSignals += p.signals.total;
        totalPositive += p.signals.positive;
        const outcome = outcomesMap.get(p.patternId);
        if (outcome) {
            totalUsage += outcome.usageCount;
            totalSuccess += outcome.successCount;
            totalFailures += outcome.failureCount;
        }
    }
    const patternAcceptanceRate = totalSignals > 0 ? totalPositive / totalSignals : 0;
    const successRate = totalUsage > 0 ? totalSuccess / totalUsage : 0;
    const failureRate = totalUsage > 0 ? totalFailures / totalUsage : 0;
    const topCategories = Object.entries(categoryCount)
        .sort((a, b) => b[1] - a[1])
        .slice(0, 5)
        .map(([cat]) => cat);
    return {
        developerId,
        languages,
        frameworks,
        projectTypes: Array.from(projectTypes),
        patternsUsed: patterns.length,
        patternAcceptanceRate,
        successRate,
        failureRate,
        topCategories,
        lastUpdated: Date.now(),
    };
}
function profileToString(p) {
    const langStr = Object.entries(p.languages)
        .sort((a, b) => b[1] - a[1])
        .map(([l, c]) => `${l}(${c})`)
        .join(', ');
    const fwStr = Object.entries(p.frameworks)
        .sort((a, b) => b[1] - a[1])
        .map(([f, c]) => `${f}(${c})`)
        .join(', ');
    return (`Developer ${p.developerId}\n` +
        `  Languages: ${langStr || '(none)'}\n` +
        `  Frameworks: ${fwStr || '(none)'}\n` +
        `  Categories: ${p.topCategories.join(', ')}\n` +
        `  Patterns: ${p.patternsUsed}\n` +
        `  Acceptance Rate: ${(p.patternAcceptanceRate * 100).toFixed(1)}%\n` +
        `  Success Rate: ${(p.successRate * 100).toFixed(1)}%\n` +
        `  Failure Rate: ${(p.failureRate * 100).toFixed(1)}%`);
}
//# sourceMappingURL=developer-profile.js.map