"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeProps = computeProps;
const get_item_thumbnail_url_1 = require("../../resources/get-item-thumbnail-url");
const processEntityFeatures_1 = require("../../permissions/_internal/processEntityFeatures");
const PageBusinessRules_1 = require("./PageBusinessRules");
const computeItemProps_1 = require("../../core/_internal/computeItemProps");
const computeLinks_1 = require("./computeLinks");
const applyPageMigrations_1 = require("./applyPageMigrations");
/**
 * Given a model and a page, set various computed properties that can't be directly mapped
 * @private
 * @param model
 * @param page
 * @param requestOptions
 * @returns
 */
function computeProps(model, page, requestOptions) {
    var _a;
    let token;
    // istanbul ignore next - this logic is covered elsewhere and should be refactored into a shared util
    if (requestOptions.authentication) {
        const session = requestOptions.authentication;
        token = session.token;
    }
    // compute base properties on page
    page = (0, computeItemProps_1.computeItemProps)(model.item, page);
    // thumbnail url
    const thumbnailUrl = (0, get_item_thumbnail_url_1.getItemThumbnailUrl)(model.item, requestOptions, token);
    // TODO: Remove this once opendata-ui starts using `links.thumbnail` instead
    page.thumbnailUrl = thumbnailUrl;
    page.links = (0, computeLinks_1.computeLinks)(model.item, requestOptions);
    /**
     * Features that can be disabled by the entity owner
     * NOTE: Pages do not have any features that can be disabled
     */
    page.features = (0, processEntityFeatures_1.processEntityFeatures)(((_a = model.data.settings) === null || _a === void 0 ? void 0 : _a.features) || {}, PageBusinessRules_1.PageDefaultFeatures);
    // Apply migrations
    page = (0, applyPageMigrations_1.applyPageMigrations)(page);
    // cast b/c this takes a partial but returns a full page
    return page;
}
//# sourceMappingURL=computeProps.js.map