import { getDefaultEntitySettings } from "../discussions/api/settings/getDefaultEntitySettings";
import { fetchSettingV2 } from "../discussions/api/settings/settings";
import { fetchModelFromItem } from "../models/fetchModelFromItem";
import { modelToHubEditableContent } from "./modelToHubEditableContent";
/**
 * Convert an Item to an editable Hub Content object,
 * fetch any additional information from Portal that may be required
 */
export const convertItemToContentPortal = async (item, requestOptions, enrichments) => {
    const model = await 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 fetchSettingV2(Object.assign({ id: item.id }, requestOptions)).catch(() => (Object.assign({ id: null }, getDefaultEntitySettings("content"))));
    }
    model.entitySettings = entitySettings;
    const content = modelToHubEditableContent(model, requestOptions, enrichments);
    return content;
};
//# sourceMappingURL=convertItemToContentPortal.js.map