"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeProps = computeProps;
const processEntityFeatures_1 = require("../../permissions/_internal/processEntityFeatures");
const ProjectBusinessRules_1 = require("./ProjectBusinessRules");
const computeLinks_1 = require("./computeLinks");
const computeItemProps_1 = require("../../core/_internal/computeItemProps");
const applyProjectMigrations_1 = require("./applyProjectMigrations");
const get_item_thumbnail_url_1 = require("../../resources/get-item-thumbnail-url");
const upgradeCatalogSchema_1 = require("../../search/upgradeCatalogSchema");
/**
 * Given a model and a project, set various computed properties that can't be directly mapped
 * @private
 * @param model
 * @param project
 * @param requestOptions
 * @returns
 */
function computeProps(model, project, requestOptions) {
    var _a, _b;
    let token;
    if (requestOptions.authentication) {
        const session = requestOptions.authentication;
        token = session.token;
    }
    // compute base properties on project
    project = (0, computeItemProps_1.computeItemProps)(model.item, project);
    // thumbnail url
    project.thumbnailUrl = (0, get_item_thumbnail_url_1.getItemThumbnailUrl)(model.item, requestOptions, token);
    project.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
    project.catalog = (0, upgradeCatalogSchema_1.upgradeCatalogSchema)(project.catalog || {});
    /**
     * Features that can be disabled by the entity owner
     */
    project.features = (0, processEntityFeatures_1.processEntityFeatures)(((_b = model.data.settings) === null || _b === void 0 ? void 0 : _b.features) || {}, ProjectBusinessRules_1.ProjectDefaultFeatures);
    project.links = (0, computeLinks_1.computeLinks)(model.item, requestOptions);
    // apply migrations
    project = (0, applyProjectMigrations_1.applyProjectMigrations)(project);
    // cast b/c this takes a partial but returns a full project
    return project;
}
//# sourceMappingURL=computeProps.js.map