"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeCatalogScope = serializeCatalogScope;
const upgradeCatalogSchema_1 = require("./upgradeCatalogSchema");
const utils_1 = require("./utils");
const serializeQueryForPortal_1 = require("./serializeQueryForPortal");
/**
 * Serialize the catalog scope into search options.
 * This is explicitly exported for other ArcGIS platform
 * applications that need to work with Hub Catalogs.
 * @param catalog The catalog to serialize
 * @param scope The scope to serialize
 * @returns The serialized search options
 */
function serializeCatalogScope(catalog, scope) {
    // apply any catalog schema migrations
    const upgraded = (0, upgradeCatalogSchema_1.upgradeCatalogSchema)(catalog);
    // get the scope
    const scopeQuery = upgraded.scopes[scope];
    if (!scopeQuery) {
        throw new Error(`No query found for scope: ${scope}`);
    }
    // apply any expansions
    const updatedQuery = (0, utils_1.expandPortalQuery)(scopeQuery);
    // Serialize into a structure compatible with the portal search
    return (0, serializeQueryForPortal_1.serializeQueryForPortal)(updatedQuery);
}
//# sourceMappingURL=serializeCatalogScopeQuery.js.map