"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCatalogFromSiteModel = getCatalogFromSiteModel;
const util_1 = require("../util");
const applyCatalogStructureMigration_1 = require("./_internal/applyCatalogStructureMigration");
const applyDefaultCollectionMigration_1 = require("./_internal/applyDefaultCollectionMigration");
/**
 * Gets new catalog from site model
 *
 * Catalog migration is performed from legacy catalog in `data.catalog`
 * if new catalog in `data.catalogV2` is not present in site's model.
 * Otherwise, new catalog in `data.catalogV2` is returned as is.
 *
 * @param {IModel} model
 * @returns {IHubCatalog}
 */
function getCatalogFromSiteModel(model) {
    // data.catalogV2 contains site's updated catalog
    if (model.data.catalogV2) {
        return model.data.catalogV2;
    }
    let migrated = (0, util_1.cloneObject)(model);
    // Ensure we have the new Catalog structure
    migrated = (0, applyCatalogStructureMigration_1.applyCatalogStructureMigration)(migrated);
    // Add default collections while preserving configuration from `data.values.searchCategories`
    migrated = (0, applyDefaultCollectionMigration_1.applyDefaultCollectionMigration)(migrated);
    return migrated.data.catalog;
}
//# sourceMappingURL=get-catalog-from-site-model.js.map