/** Map a Spec to an ExecutiveSummarySpecEntry. */
export function extractSpecEntries(specs) {
    return specs.map((spec) => {
        const entry = {
            id: spec.id,
            title: spec.title,
            status: spec.status,
            difficulty: spec.difficulty,
            risk: spec.risk,
            devHours: spec.estimation.devHours,
            reviewHours: spec.estimation.reviewHours,
            totalCostUsd: spec.estimation.totalCostUsd,
            tags: spec.tags,
        };
        if (spec.actuals !== null) {
            entry.actualDevHours = spec.actuals.devHours;
            entry.actualTotalCostUsd = spec.actuals.totalCostUsd;
            entry.completedAt = spec.actuals.completedAt;
        }
        return entry;
    });
}
/** Sum all estimation fields across all specs. */
export function aggregateEstimation(specs) {
    let totalDevHours = 0;
    let totalReviewHours = 0;
    let totalHumanCostUsd = 0;
    let totalApiCostUsd = 0;
    let totalCostUsd = 0;
    for (const spec of specs) {
        totalDevHours += spec.estimation.devHours;
        totalReviewHours += spec.estimation.reviewHours;
        totalHumanCostUsd += spec.estimation.humanCostUsd;
        totalApiCostUsd += spec.estimation.apiCostUsd;
        totalCostUsd += spec.estimation.totalCostUsd;
    }
    return {
        totalDevHours,
        totalReviewHours,
        totalHumanCostUsd,
        totalApiCostUsd,
        totalCostUsd,
        specCount: specs.length,
    };
}
/** Count specs by risk level; highlights = titles of high/critical specs. */
export function buildRiskProfile(specs) {
    let low = 0;
    let medium = 0;
    let high = 0;
    let critical = 0;
    const highlights = [];
    for (const spec of specs) {
        switch (spec.risk) {
            case 'low':
                low++;
                break;
            case 'medium':
                medium++;
                break;
            case 'high':
                high++;
                highlights.push(spec.title);
                break;
            case 'critical':
                critical++;
                highlights.push(spec.title);
                break;
        }
    }
    return { low, medium, high, critical, highlights };
}
/** Extract architecture snapshot from ProjectKnowledge. */
export function buildArchitectureSnapshot(knowledge) {
    const layers = knowledge.architecture.layers.map((l) => l.name);
    return {
        language: knowledge.language,
        framework: knowledge.framework ?? 'none',
        database: knowledge.database,
        layers,
    };
}
/** Orchestrate all extractors to build the full ExecutiveSummaryData. */
export function buildExecutiveSummaryData(knowledge, specs) {
    const pathSegments = knowledge.projectPath.split('/');
    const projectName = pathSegments[pathSegments.length - 1] ?? knowledge.projectPath;
    return {
        projectName,
        generatedAt: new Date().toISOString(),
        architecture: buildArchitectureSnapshot(knowledge),
        specs: extractSpecEntries(specs),
        estimation: aggregateEstimation(specs),
        riskProfile: buildRiskProfile(specs),
    };
}
//# sourceMappingURL=data-extractors.js.map