// engine/mermaid/helpers.ts — Shared helpers for mermaid diagram generation.
// Extracted from mermaid-generator.ts to keep file sizes within limits.
/** Checks if a scope meets or exceeds a threshold in the scope ordering. */
export function isScopeAtLeast(scope, threshold) {
    const order = {
        trivial: 0,
        feature: 1,
        'cross-module': 2,
        architectural: 3,
    };
    return order[scope] >= order[threshold];
}
/** Builds layer nodes for data flow diagrams based on target and knowledge. */
export function buildLayers(target, knowledge) {
    // If knowledge has real architecture layers, prefer them over target-inferred ones
    if (knowledge && knowledge.architecture.layers.length > 0) {
        return knowledge.architecture.layers.map((l) => ({
            id: l.name.replace(/[^a-zA-Z0-9]/g, '_'),
            label: l.name,
        }));
    }
    const framework = knowledge?.framework ?? '';
    const layers = [];
    if (target === 'frontend' || target === 'fullstack') {
        layers.push({ id: 'Client', label: framework ? `Client (${framework})` : 'Client' });
    }
    if (target !== 'database' && target !== 'infrastructure') {
        layers.push({ id: 'Action', label: 'Action/Controller' });
        layers.push({ id: 'Service', label: 'Service' });
    }
    if (target === 'backend' || target === 'fullstack' || target === 'database') {
        layers.push({ id: 'Repo', label: 'Repository' });
        const dbRaw = knowledge?.database ?? 'DB';
        const db = dbRaw === 'unknown' ? 'DB' : dbRaw;
        layers.push({ id: 'DB', label: db });
    }
    if (target === 'infrastructure') {
        layers.push({ id: 'Infra', label: 'Infrastructure' });
        layers.push({ id: 'Cloud', label: 'Cloud Provider' });
    }
    // Fallback if empty
    if (layers.length === 0) {
        layers.push({ id: 'Input', label: 'Input' }, { id: 'Process', label: 'Process' }, { id: 'Output', label: 'Output' });
    }
    return layers;
}
/** Builds participant nodes for sequence diagrams based on target and knowledge. */
export function buildParticipants(target, knowledge) {
    const participants = [];
    if (target === 'frontend' || target === 'fullstack') {
        participants.push({ id: 'UI', label: 'UI' });
    }
    participants.push({ id: 'API', label: 'API' });
    participants.push({ id: 'SVC', label: 'Service' });
    if (target === 'backend' || target === 'fullstack' || target === 'database') {
        const db = knowledge?.database ?? 'DB';
        participants.push({ id: 'DB', label: db });
    }
    return participants;
}
//# sourceMappingURL=helpers.js.map