"use strict";
/**
 * Overall weighted rollup across the six dimension scores.
 *
 * Produces the headline number + letter the customer sees first
 * (dashboard banner, CLI summary line), the rating-tier letter
 * derived from that score via the uniform thresholds in
 * `thresholds.ts`, and a cross-dimension `topActions[]` list
 * sorted by weighted score-impact so the customer sees the
 * single best move across all dimensions.
 *
 * Dimension weights (sum to 1.0):
 *   Testing                25%
 *   Quality                20%
 *   Security               20%
 *   Developer Experience   15%
 *   Documentation          10%
 *   Maintainability        10%
 *
 * Cross-dimension `topActions[]` ranks each dimension's
 * top-action by its weighted contribution to the overall score
 * (`upliftIfFixed * dimensionWeight`). Customers reading the
 * health report's top-of-document recommendation see the single
 * fix that lifts the overall number most — regardless of which
 * dimension it lives in.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.DIMENSION_LABEL = exports.DIMENSION_WEIGHTS = void 0;
exports.computeOverall = computeOverall;
const thresholds_1 = require("./thresholds");
exports.DIMENSION_WEIGHTS = {
    testing: 0.25,
    quality: 0.2,
    security: 0.2,
    developerExperience: 0.15,
    documentation: 0.1,
    maintainability: 0.1,
};
/** Human-readable label for renderers. */
exports.DIMENSION_LABEL = {
    testing: 'Testing',
    quality: 'Code Quality',
    security: 'Security',
    developerExperience: 'Developer Experience',
    documentation: 'Documentation',
    maintainability: 'Maintainability',
};
/**
 * Compute the weighted overall score, rating letter, and cross-
 * dimension top-actions list from the six per-dimension scores.
 */
function computeOverall(dimensions, options = {}) {
    const overallScore = Math.round(Object.entries(exports.DIMENSION_WEIGHTS).reduce((sum, [id, w]) => sum + dimensions[id].score * w, 0));
    const crossActions = [];
    for (const id of Object.keys(exports.DIMENSION_WEIGHTS)) {
        const dim = dimensions[id];
        if (!dim.topActions)
            continue;
        for (const action of dim.topActions) {
            crossActions.push({
                ...action,
                dimension: id,
                dimensionLabel: exports.DIMENSION_LABEL[id],
                weightedUplift: action.upliftIfFixed * exports.DIMENSION_WEIGHTS[id],
            });
        }
    }
    crossActions.sort((a, b) => b.weightedUplift - a.weightedUplift);
    const limit = options.topActionsLimit ?? 10;
    return {
        overallScore,
        rating: (0, thresholds_1.ratingFromScore)(overallScore),
        topActions: crossActions.slice(0, limit),
    };
}
//# sourceMappingURL=overall.js.map