"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeProps = computeProps;
const get_item_thumbnail_url_1 = require("../../resources/get-item-thumbnail-url");
const upgradeCatalogSchema_1 = require("../../search/upgradeCatalogSchema");
const processEntityFeatures_1 = require("../../permissions/_internal/processEntityFeatures");
const SiteBusinessRules_1 = require("./SiteBusinessRules");
const computeItemProps_1 = require("../../core/_internal/computeItemProps");
const computeLinks_1 = require("./computeLinks");
const get_catalog_from_site_model_1 = require("../get-catalog-from-site-model");
const get_prop_1 = require("../../objects/get-prop");
const compareAccess_1 = require("../../access/compareAccess");
/**
 * Given a model and a site, set various computed properties that can't be directly mapped
 * @private
 * @param model
 * @param site
 * @param requestOptions
 * @returns
 */
function computeProps(model, site, requestOptions) {
    var _a;
    let token;
    if (requestOptions.authentication) {
        const session = requestOptions.authentication;
        token = session.token;
    }
    // compute base properties on site
    site = (0, computeItemProps_1.computeItemProps)(model.item, site);
    // 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
    site.thumbnailUrl = thumbnailUrl;
    site.links = (0, computeLinks_1.computeLinks)(model.item, requestOptions);
    /**
     * Features that can be disabled by the entity owner
     */
    site.features = (0, processEntityFeatures_1.processEntityFeatures)(((_a = model.data.settings) === null || _a === void 0 ? void 0 : _a.features) || {}, SiteBusinessRules_1.SiteDefaultFeatures);
    // Get new catalog structure
    site.catalog = (0, get_catalog_from_site_model_1.getCatalogFromSiteModel)(model);
    // Perform schema upgrades on the new catalog structure
    site.catalog = (0, upgradeCatalogSchema_1.upgradeCatalogSchema)(site.catalog);
    // Determine if the site is still using the legacy v1 catalog
    site.isCatalogV1Enabled = !!model.data.catalog;
    // Update the hub assistant's access level based on the site's access level if needed
    // Cannot have a sites access level be private while the hub assistant level is org or public
    if ((0, get_prop_1.getProp)(site, "assistant.access")) {
        site.assistant.access = (0, compareAccess_1.compareAccess)(site.assistant.access, site.access);
    }
    // cast b/c this takes a partial but returns a full site
    return site;
}
//# sourceMappingURL=computeProps.js.map