"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchHubContent = void 0;
const fetchEditableContentEnrichments_1 = require("./_internal/fetchEditableContentEnrichments");
const compose_1 = require("./compose");
const set_prop_1 = require("../objects/set-prop");
const fetchContent_1 = require("./fetchContent");
const convertItemToContent_1 = require("./convertItemToContent");
/**
 * fetch a content entity by identifier
 * Currently used in arcgis-hub-add-content component, and the Ember content service
 * @param identifier
 * @param requestOptions
 * @returns content entity
 */
const fetchHubContent = async (identifier, requestOptions, enrichments) => {
    // NOTE: b/c we have to support slugs, we use fetchContent() to get the item
    // by telling it to not fetch any enrichments. We then can fetch enrichments
    // as needed after we have the item
    const options = Object.assign(Object.assign({}, requestOptions), { enrichments: [] });
    const { item } = await (0, fetchContent_1.fetchContent)(identifier, options);
    const editableContentEnrichments = await (0, fetchEditableContentEnrichments_1.fetchEditableContentEnrichments)(item, requestOptions, enrichments);
    // we must normalize the underlying item type to account
    // for older items (e.g. sites that are type "Web Mapping
    // Application") before we map the model to a Hub Entity
    const type = (0, compose_1.normalizeItemType)(item);
    (0, set_prop_1.setProp)("type", type, item);
    return (0, convertItemToContent_1.convertItemToContent)(item, requestOptions, editableContentEnrichments);
};
exports.fetchHubContent = fetchHubContent;
//# sourceMappingURL=fetchHubContent.js.map