function technicalScore(ctx) {
    const score = ctx.difficulty;
    return {
        dimension: 'technical',
        score,
        justification: `Difficulty level ${score}/5 maps directly to technical complexity`,
    };
}
function integrationScore(ctx) {
    let base;
    const f = ctx.fileCount;
    if (f <= 3) {
        base = 1;
    }
    else if (f <= 6) {
        base = 2;
    }
    else if (f <= 10) {
        base = 3;
    }
    else if (f <= 15) {
        base = 4;
    }
    else {
        base = 5;
    }
    const depFactor = ctx.dependencyCount > 5 ? 1 : 0;
    const score = Math.min(base + depFactor, 5);
    return {
        dimension: 'integration',
        score,
        justification: `${f} files (base ${base}) + dependency factor ${depFactor}`,
    };
}
function testingScore(ctx) {
    const scopeMap = {
        trivial: 1,
        feature: 2,
        'cross-module': 4,
        architectural: 5,
    };
    const score = scopeMap[ctx.scope] ?? 2;
    return {
        dimension: 'testing',
        score,
        justification: `Scope "${ctx.scope}" requires testing at level ${score}/5`,
    };
}
function organizationalScore(ctx) {
    const hasBreaking = ctx.tags.includes('breaking-change') || ctx.tags.includes('migration');
    const score = hasBreaking ? 4 : 2;
    return {
        dimension: 'organizational',
        score,
        justification: hasBreaking
            ? 'Contains breaking-change or migration tags requiring coordination'
            : 'No breaking changes detected',
    };
}
function uncertaintyScore(ctx) {
    let score = 2;
    if (ctx.framework === null) {
        score += 2;
    }
    // High difficulty without a known framework indicates exploratory/spike-like work
    if (ctx.difficulty >= 4 && ctx.framework === null) {
        score = Math.min(score + 1, 5);
    }
    score = Math.min(score, 5);
    return {
        dimension: 'uncertainty',
        score,
        justification: ctx.framework === null
            ? 'Unknown framework increases estimation uncertainty'
            : 'Framework known, moderate uncertainty',
    };
}
function weightedAverage(scores) {
    const weights = {
        technical: 0.3,
        integration: 0.25,
        testing: 0.2,
        organizational: 0.15,
        uncertainty: 0.1,
    };
    return scores.reduce((acc, s) => {
        const weight = weights[s.dimension];
        return acc + s.score * weight;
    }, 0);
}
/**
 * Calculate the full complexity matrix for a spec.
 */
export function calculateComplexityMatrix(ctx) {
    const scores = [
        technicalScore(ctx),
        integrationScore(ctx),
        testingScore(ctx),
        organizationalScore(ctx),
        uncertaintyScore(ctx),
    ];
    const overallComplexity = weightedAverage(scores);
    return {
        specId: ctx.specId,
        scores,
        overallComplexity,
        generatedAt: new Date().toISOString(),
    };
}
//# sourceMappingURL=complexity-calculator.js.map