"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deepCatalogContains = deepCatalogContains;
const get_prop_1 = require("../objects/get-prop");
const deepContains_1 = require("./_internal/deepContains");
/**
 * Check that a specific entity is contained within a hierarchy of catalogs
 * @param identifier id or slug of the entity to check
 * @param hubEntityType Entity type of the identifier
 * @param path definition of the containment hierarchy /site/00c/projects/cc1 etc
 * @param context
 * @param rootCatalog Optional, root level catalog to start checking from (typically the site)
 * @returns
 */
async function deepCatalogContains(identifier, hubEntityType, path, context, rootCatalog) {
    // convert to catalog infos
    let infos = [];
    try {
        infos = (0, deepContains_1.pathToCatalogInfo)(path);
    }
    catch (e) {
        return {
            identifier,
            isContained: false,
            catalogInfo: {},
            duration: 0,
            reason: (0, get_prop_1.getProp)(e, "message") || "An error occurred while parsing path.",
        };
    }
    // add the root catalog to the end of the infos as it's the last one to check
    if (rootCatalog) {
        infos = [
            ...infos,
            {
                id: "root",
                hubEntityType: "site", // debatable if this is a good idea
                catalog: rootCatalog,
            },
        ];
    }
    return (0, deepContains_1.deepContains)(identifier, hubEntityType, infos, context);
}
//# sourceMappingURL=deepCatalogContains.js.map