import { processEntityFeatures } from "../../permissions/_internal/processEntityFeatures";
import { ProjectDefaultFeatures } from "./ProjectBusinessRules";
import { computeLinks } from "./computeLinks";
import { computeItemProps } from "../../core/_internal/computeItemProps";
import { applyProjectMigrations } from "./applyProjectMigrations";
import { getItemThumbnailUrl } from "../../resources/get-item-thumbnail-url";
import { upgradeCatalogSchema } from "../../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
 */
export 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 = computeItemProps(model.item, project);
    // thumbnail url
    project.thumbnailUrl = 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 = upgradeCatalogSchema(project.catalog || {});
    /**
     * Features that can be disabled by the entity owner
     */
    project.features = processEntityFeatures(((_b = model.data.settings) === null || _b === void 0 ? void 0 : _b.features) || {}, ProjectDefaultFeatures);
    project.links = computeLinks(model.item, requestOptions);
    // apply migrations
    project = applyProjectMigrations(project);
    // cast b/c this takes a partial but returns a full project
    return project;
}
//# sourceMappingURL=computeProps.js.map