"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchesInCatalog = matchesInCatalog;
const catalogContains_1 = require("./catalogContains");
const deepCatalogContains_1 = require("./deepCatalogContains");
/**
 * Check which of the given matches are contained in the specified catalog.
 * Decorates each match with inCatalog: true|false, which the disambiguation
 * UX can then use to determine how to present the matches.
 * @param type
 * @param matches
 * @param catalog
 * @param context
 * @param path
 */
async function matchesInCatalog(type, matches, catalog, context, path) {
    // check each match for containment
    const results = await Promise.all(matches.map(async (match) => {
        // if we got a path, use deepCatalogContains otherwise use catalogContains
        let isContained = false;
        if (path) {
            const deepResult = await (0, deepCatalogContains_1.deepCatalogContains)(match.id, type, path, context, catalog);
            isContained = deepResult.isContained;
        }
        else {
            const catalogResult = await (0, catalogContains_1.catalogContains)(match.id, catalog, context, { hubEntityType: type });
            isContained = catalogResult.isContained;
        }
        return Object.assign(Object.assign({}, match), { inCatalog: isContained });
    }));
    return results;
}
//# sourceMappingURL=matchesInCatalog.js.map