"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._migrateToV2Catalog = _migrateToV2Catalog;
const get_prop_1 = require("../../objects/get-prop");
const set_prop_1 = require("../../objects/set-prop");
const util_1 = require("../../util");
const get_catalog_from_site_model_1 = require("../get-catalog-from-site-model");
/**
 * Adds a new `catalogV2` property to the site model, which is a migrated version of the existing catalog.
 * @private
 * @param {object} model Site Model
 * @returns {object}
 */
function _migrateToV2Catalog(model) {
    const newSchemaVersion = 1.9;
    // do nothing if migration already applied
    if ((0, get_prop_1.getProp)(model, "item.properties.schemaVersion") >= newSchemaVersion) {
        return model;
    }
    // apply migration
    const clone = (0, util_1.cloneObject)(model);
    const newCatalog = (0, get_catalog_from_site_model_1.getCatalogFromSiteModel)(clone);
    clone.data.catalogV2 = newCatalog;
    // increment schemaVersion
    (0, set_prop_1.setProp)("item.properties.schemaVersion", newSchemaVersion, clone);
    return clone;
}
//# sourceMappingURL=_migrate-to-v2-catalog.js.map