"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateArchitectureDiagrams = generateArchitectureDiagrams;
const architectureMap_1 = require("./architectureMap");
function sortUnique(values) {
    return [...new Set(values)].sort((left, right) => left.localeCompare(right));
}
async function generateArchitectureDiagrams(workspaceRoot) {
    const map = await (0, architectureMap_1.generateArchitectureMap)(workspaceRoot);
    const hotspotByModule = new Map(map.moduleHotspotSummary
        .map((entry) => [entry.moduleName, entry])
        .sort(([left], [right]) => left.localeCompare(right)));
    const modules = [...map.modules]
        .sort((left, right) => left.moduleName.localeCompare(right.moduleName))
        .map((moduleEntry) => {
        const hotspot = hotspotByModule.get(moduleEntry.moduleName);
        return {
            name: moduleEntry.moduleName,
            path: moduleEntry.sourcePath,
            incomingDependencyCount: hotspot?.incomingDependencyCount ?? 0,
            outgoingDependencyCount: hotspot?.outgoingDependencyCount ?? 0,
            participatesInCycle: hotspot?.participatesInCycle ?? false,
            orphan: hotspot?.orphan ?? false,
        };
    });
    const edges = [...map.edges]
        .sort((left, right) => {
        const sourceCompare = left.source.localeCompare(right.source);
        if (sourceCompare !== 0) {
            return sourceCompare;
        }
        return left.target.localeCompare(right.target);
    })
        .map((edge) => ({
        source: edge.source,
        target: edge.target,
        importCount: edge.importCount,
    }));
    const cycles = [...map.cycles]
        .map((cycle) => [...cycle])
        .sort((left, right) => left.join('->').localeCompare(right.join('->')));
    const orphanModules = sortUnique(modules.filter((moduleEntry) => moduleEntry.orphan).map((moduleEntry) => moduleEntry.name));
    const highDependencyModules = sortUnique(modules
        .filter((moduleEntry) => moduleEntry.incomingDependencyCount >= 3)
        .map((moduleEntry) => moduleEntry.name));
    return {
        diagramVersion: 1,
        projectName: map.projectName,
        generatedAtUtc: map.generatedAtUtc,
        modules,
        edges,
        cycles,
        orphanModules,
        highDependencyModules,
    };
}
//# sourceMappingURL=generateArchitectureDiagrams.js.map