// Planu — Sustainability score engine (SPEC-482)
// Score = simplicity × cohesion / (1 + coupling) × 100
import { computeFileSimplicity, scoreToGrade } from './simplicity.js';
import { computeCohesion } from './cohesion.js';
import { computeCoupling } from './coupling.js';
/** Compute sustainability for a single file. */
export function computeModuleSustainability(filePath, allFilePaths) {
    const simplicityMetrics = computeFileSimplicity(filePath);
    const simplicityScore = simplicityMetrics !== null ? simplicityMetrics.score / 100 : 0.5;
    // simplicity: invert complexity so higher = simpler
    const simplicity = simplicityScore;
    const cohesion = computeCohesion(filePath);
    const coupling = computeCoupling(filePath, allFilePaths);
    const rawScore = (simplicity * cohesion) / (1 + coupling / 10);
    const score = Math.max(0, Math.min(100, Math.round(rawScore * 100)));
    const parts = filePath.replace(/\\/g, '/').split('/');
    const relFile = parts.slice(-3).join('/');
    return {
        file: relFile,
        simplicity: Math.round(simplicity * 100) / 100,
        cohesion: Math.round(cohesion * 100) / 100,
        coupling,
        score,
        grade: scoreToGrade(score),
    };
}
/** Compute sustainability report for all given files. */
export function computeSustainabilityReport(projectPath, filePaths) {
    const modules = filePaths
        .map((fp) => computeModuleSustainability(fp, filePaths))
        .sort((a, b) => a.score - b.score); // worst first
    const overallScore = modules.length > 0
        ? Math.round(modules.reduce((sum, m) => sum + m.score, 0) / modules.length)
        : 0;
    return {
        projectPath,
        overallScore,
        overallGrade: scoreToGrade(overallScore),
        modules,
        filesAnalyzed: filePaths.length,
        generatedAt: new Date().toISOString(),
    };
}
//# sourceMappingURL=sustainability.js.map