"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeProps = computeProps;
const processEntityFeatures_1 = require("../../permissions/_internal/processEntityFeatures");
const InitiativeBusinessRules_1 = require("./InitiativeBusinessRules");
const computeLinks_1 = require("./computeLinks");
const computeItemProps_1 = require("../../core/_internal/computeItemProps");
const upgradeCatalogSchema_1 = require("../../search/upgradeCatalogSchema");
const get_item_thumbnail_url_1 = require("../../resources/get-item-thumbnail-url");
/**
 * Given a model and an Initiative, set various computed properties that can't be directly mapped
 * @private
 * @param model
 * @param initiative
 * @param requestOptions
 * @returns
 */
function computeProps(model, initiative, requestOptions) {
    var _a, _b;
    let token;
    if (requestOptions.authentication) {
        const session = requestOptions.authentication;
        token = session.token;
    }
    // compute base properties on initiative
    initiative = (0, computeItemProps_1.computeItemProps)(model.item, initiative);
    // thumbnail url
    initiative.thumbnailUrl = (0, get_item_thumbnail_url_1.getItemThumbnailUrl)(model.item, requestOptions, token);
    initiative.view = Object.assign(Object.assign({}, model.data.view), { featuredImageUrl: (_a = model.data.view) === null || _a === void 0 ? void 0 : _a.featuredImageUrl });
    // Ensure we have a catalog and that its at the current schema
    initiative.catalog = (0, upgradeCatalogSchema_1.upgradeCatalogSchema)(initiative.catalog || {});
    /**
     * Features that can be disabled by the entity owner
     */
    initiative.features = (0, processEntityFeatures_1.processEntityFeatures)(((_b = model.data.settings) === null || _b === void 0 ? void 0 : _b.features) || {}, InitiativeBusinessRules_1.InitiativeDefaultFeatures);
    initiative.links = (0, computeLinks_1.computeLinks)(model.item, requestOptions);
    // cast b/c this takes a partial but returns a full object
    return initiative;
}
//# sourceMappingURL=computeProps.js.map