"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertItemToContentPortal = void 0;
const getDefaultEntitySettings_1 = require("../discussions/api/settings/getDefaultEntitySettings");
const settings_1 = require("../discussions/api/settings/settings");
const fetchModelFromItem_1 = require("../models/fetchModelFromItem");
const modelToHubEditableContent_1 = require("./modelToHubEditableContent");
/**
 * Convert an Item to an editable Hub Content object,
 * fetch any additional information from Portal that may be required
 */
const convertItemToContentPortal = async (item, requestOptions, enrichments) => {
    const model = await (0, fetchModelFromItem_1.fetchModelFromItem)(item, requestOptions);
    // Now handle the entity settings
    let entitySettings;
    // if the discussion service, fetch them, otherwise use defaults
    if (requestOptions && !requestOptions.isPortal) {
        entitySettings = null;
    }
    else {
        entitySettings = await (0, settings_1.fetchSettingV2)(Object.assign({ id: item.id }, requestOptions)).catch(() => (Object.assign({ id: null }, (0, getDefaultEntitySettings_1.getDefaultEntitySettings)("content"))));
    }
    model.entitySettings = entitySettings;
    const content = (0, modelToHubEditableContent_1.modelToHubEditableContent)(model, requestOptions, enrichments);
    return content;
};
exports.convertItemToContentPortal = convertItemToContentPortal;
//# sourceMappingURL=convertItemToContentPortal.js.map