"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RankingEngine = void 0;
class RankingEngine {
    rank(patterns) {
        const now = Date.now();
        const scored = patterns.map((p) => {
            const confidenceScore = (p.confidence?.mean || 0) * 100;
            const qualityScore = p.quality?.score || 0;
            const usageScore = Math.min((p.signals?.total || 0) * 2, 100);
            const daysSinceSignal = Math.max((now - (p.signals?.lastSignal || now)) / (1000 * 60 * 60 * 24), 0);
            const recencyScore = Math.max(0, 100 - daysSinceSignal * 2);
            const acceptanceScore = Math.min(((p.signals?.positive || 0) / Math.max((p.signals?.total || 1), 1)) * 100, 100);
            const score = Math.round(confidenceScore * 0.30 +
                qualityScore * 0.25 +
                usageScore * 0.15 +
                recencyScore * 0.15 +
                acceptanceScore * 0.15);
            return {
                ...p,
                ranking: {
                    score: Math.min(score, 100),
                    rank: 0,
                    factors: {
                        confidence: Math.round(confidenceScore),
                        quality: qualityScore,
                        usage: Math.round(usageScore),
                        recency: Math.round(recencyScore),
                        acceptance: Math.round(acceptanceScore),
                    },
                },
            };
        });
        scored.sort((a, b) => b.ranking.score - a.ranking.score);
        scored.forEach((p, i) => { p.ranking.rank = i + 1; });
        return scored;
    }
}
exports.RankingEngine = RankingEngine;
//# sourceMappingURL=pattern-ranking.js.map