(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "./discriminator-utils", "./resource-operation-extractor"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.toLeanNodeType = toLeanNodeType;
    const discriminator_utils_1 = require("./discriminator-utils");
    const resource_operation_extractor_1 = require("./resource-operation-extractor");
    function getVersions(node) {
        return Array.isArray(node.version) ? node.version : [node.version];
    }
    function buildVersionDiscriminators(node) {
        const out = new Map();
        for (const version of getVersions(node)) {
            out.set(version, {
                resourceOperations: (0, resource_operation_extractor_1.extractResourceOperations)(node, version, undefined, {
                    fields: { description: true, builderHint: true },
                }),
                modeDiscriminator: (0, discriminator_utils_1.extractModeDiscriminator)(node, version),
                operationDiscriminator: (0, discriminator_utils_1.extractOperationOnlyDiscriminator)(node, version),
            });
        }
        return out;
    }
    function toLeanNodeType(node) {
        const lean = {
            name: node.name,
            displayName: node.displayName,
            description: node.description,
            version: node.version,
            group: node.group,
            inputs: node.inputs,
            outputs: node.outputs,
            discriminatorsByVersion: buildVersionDiscriminators(node),
        };
        if (node.codex?.alias) {
            lean.codex = { alias: node.codex.alias };
        }
        if (node.builderHint) {
            const { searchHint, relatedNodes, inputs } = node.builderHint;
            const hint = {};
            if (searchHint !== undefined)
                hint.searchHint = searchHint;
            if (relatedNodes !== undefined)
                hint.relatedNodes = relatedNodes;
            if (inputs !== undefined)
                hint.inputs = inputs;
            if (Object.keys(hint).length > 0)
                lean.builderHint = hint;
        }
        return lean;
    }
});
//# sourceMappingURL=lean-node-type.js.map