function count(x) {
    return Array.isArray(x) ? x.length : 0;
}
function summarizeImports(imports) {
    if (!Array.isArray(imports))
        return [];
    return imports.map((imp) => {
        const e = (imp ?? {});
        const out = {
            select: Array.isArray(e['select']) ? e['select'].map((s) => String(s)) : [],
        };
        if (typeof e['from'] === 'string')
            out.from = e['from'];
        if (typeof e['package'] === 'string')
            out.package = e['package'];
        if (typeof e['file'] === 'string')
            out.file = e['file'];
        if (typeof e['version'] === 'string')
            out.version = e['version'];
        return out;
    });
}
function summarizeExports(exportsVal) {
    if (Array.isArray(exportsVal)) {
        return exportsVal
            .map((x) => (typeof x === 'string' ? x : String(x?.name ?? '')))
            .filter(Boolean);
    }
    if (exportsVal && typeof exportsVal === 'object') {
        return Object.keys(exportsVal);
    }
    return [];
}
function summarizeComponent(c) {
    return {
        name: c.name,
        version: c.version,
        description: c.description,
        tags: Array.isArray(c.tags) ? c.tags.map((t) => String(t)) : [],
        models: count(c.models),
        controllers: count(c.controllers),
        services: count(c.services),
        views: count(c.views),
        events: count(c.events),
        imports: summarizeImports(c.imports),
        exports: summarizeExports(c.exports),
    };
}
function names(arr) {
    if (!Array.isArray(arr))
        return [];
    return arr
        .map((x) => x?.name)
        .filter((n) => typeof n === 'string');
}
/**
 * Build the `--json` "useful" summary from a parsed AST + the source's
 * top-level name/specVersion (which the AST root drops — the parser threads
 * them onto its result).
 */
export function summarizeSpecForCli(ast, opts = {}) {
    const components = Array.isArray(ast?.components) ? ast.components : [];
    const manifests = Array.isArray(ast?.manifests) ? ast.manifests : [];
    const hasCapabilityMappings = manifests.some((m) => count(m.capabilityMappings) > 0);
    const hasInstanceFactories = manifests.some((m) => count(m.instanceFactories) > 0);
    return {
        name: opts.specName,
        specVersion: opts.specVersion,
        components: components.map(summarizeComponent),
        deployments: names(ast?.deployments),
        manifests: names(ast?.manifests),
        hasCapabilityMappings,
        hasInstanceFactories,
    };
}
//# sourceMappingURL=spec-summary.js.map