"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.upgradeSiteSchema = upgradeSiteSchema;
const get_prop_1 = require("../objects/get-prop");
const site_schema_version_1 = require("./site-schema-version");
const _apply_site_schema_1 = require("./_internal/_apply-site-schema");
const _enforce_lowercase_domains_1 = require("./_internal/_enforce-lowercase-domains");
const _ensure_catalog_1 = require("./_internal/_ensure-catalog");
const _purge_non_guids_from_catalog_1 = require("./_internal/_purge-non-guids-from-catalog");
const _ensure_telemetry_1 = require("./_internal/_ensure-telemetry");
const _migrate_feed_config_1 = require("./_internal/_migrate-feed-config");
const _migrate_event_list_card_configs_1 = require("./_internal/_migrate-event-list-card-configs");
const migrateLegacyCapabilitiesToFeatures_1 = require("./_internal/capabilities/migrateLegacyCapabilitiesToFeatures");
const _migrate_telemetry_config_1 = require("./_internal/_migrate-telemetry-config");
const migrateBadBasemap_1 = require("./_internal/migrateBadBasemap");
const ensureBaseTelemetry_1 = require("./_internal/ensureBaseTelemetry");
const migrateWebMappingApplicationSites_1 = require("./_internal/migrateWebMappingApplicationSites");
const _migrate_link_underlines_capability_1 = require("./_internal/_migrate-link-underlines-capability");
const _migrate_to_v2_catalog_1 = require("./_internal/_migrate-to-v2-catalog");
const ensureLowercaseOrgUrlKeySlugAndKeyword_1 = require("./_internal/ensureLowercaseOrgUrlKeySlugAndKeyword");
const migrateEnsureHeaderComponentName_1 = require("./_internal/migrateEnsureHeaderComponentName");
/**
 * Upgrades the schema upgrades
 * @param model IModel
 */
function upgradeSiteSchema(model) {
    // WARNING - If you are writing a site schema migration,
    // you probably need to apply it to site drafts as well!
    // Specifically, add the migration to upgrade-draft-schema.ts file
    // in the sites package.
    // See https://github.com/Esri/hub.js/issues/498 for more details.
    if ((0, get_prop_1.getProp)(model, "item.properties.schemaVersion") !== site_schema_version_1.SITE_SCHEMA_VERSION) {
        // apply upgrade functions in order...
        model = (0, _apply_site_schema_1._applySiteSchema)(model);
        model = (0, _enforce_lowercase_domains_1._enforceLowercaseDomains)(model);
        model = (0, _ensure_catalog_1._ensureCatalog)(model);
        model = (0, _purge_non_guids_from_catalog_1._purgeNonGuidsFromCatalog)(model);
        model = (0, _ensure_telemetry_1._ensureTelemetry)(model);
        model = (0, _migrate_feed_config_1._migrateFeedConfig)(model);
        model = (0, _migrate_event_list_card_configs_1._migrateEventListCardConfigs)(model);
        model = (0, migrateLegacyCapabilitiesToFeatures_1.migrateLegacyCapabilitiesToFeatures)(model);
        model = (0, _migrate_telemetry_config_1._migrateTelemetryConfig)(model);
        model = (0, _migrate_to_v2_catalog_1._migrateToV2Catalog)(model);
    }
    // apply versionless migrations
    model = (0, migrateBadBasemap_1.migrateBadBasemap)(model);
    model = (0, ensureBaseTelemetry_1.ensureBaseTelemetry)(model);
    model = (0, migrateWebMappingApplicationSites_1.migrateWebMappingApplicationSites)(model);
    model = (0, _migrate_link_underlines_capability_1._migrateLinkUnderlinesCapability)(model);
    model = (0, ensureLowercaseOrgUrlKeySlugAndKeyword_1.ensureLowercaseOrgUrlKeySlugAndKeyword)(model);
    model = (0, migrateEnsureHeaderComponentName_1.migrateEnsureHeaderComponentName)(model);
    return model;
}
//# sourceMappingURL=upgrade-site-schema.js.map