"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateBadBasemap = migrateBadBasemap;
const get_prop_1 = require("../../objects/get-prop");
const util_1 = require("../../util");
/**
 * During a period in late 2023 and early 2024, the python api
 * was writing a bad confirmation for basemaps as part of the site
 * cloning process. This migration will fix that.
 * @param {Object} model Site Model
 * @private
 */
function migrateBadBasemap(model) {
    // Unlike other migrations, this is not based on a version
    // rather it checks for a bad confirmation and fixes it.
    // Early exit if the bad confirmation is not present
    if ((0, get_prop_1.getProp)(model, "data.values.map.basemaps"))
        return model;
    // Check for the bad confirmation
    if ((0, get_prop_1.getProp)(model, "data.values.map.baseMapLayers")) {
        // create a clone...
        const clone = (0, util_1.cloneObject)(model);
        // get the values we need
        const baseMapLayers = (0, get_prop_1.getProp)(model, "data.values.map.baseMapLayers");
        const title = (0, get_prop_1.getProp)(model, "data.values.map.title");
        // remove the bad props
        delete clone.data.values.map.baseMapLayers;
        delete clone.data.values.map.title;
        // assign the new structure
        clone.data.values.map.basemaps = {
            primary: {
                baseMapLayers,
                title,
            },
        };
        return clone;
    }
    else {
        // This should not happen, but if it does, just return the model
        return model;
    }
}
//# sourceMappingURL=migrateBadBasemap.js.map