"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertAllowedTypes = exports.allowedTypeFilter = void 0;
const index_js_1 = require("../../util/index.js");
const allowedTypes_js_1 = require("./allowedTypes.js");
/**
 * Filters an allowed type based on the provided options.
 * @param allowedType - The allowed type to filter.
 * @param options - The options to use for filtering.
 * @returns Whether the allowed type passes the filter.
 */
function allowedTypeFilter(allowedType, options) {
    // If the allowed type is staged, only include it if the options allow it.
    if (allowedType.metadata.stagedSchemaUpgrade !== undefined) {
        return options.includeStaged(allowedType.metadata.stagedSchemaUpgrade);
    }
    return true;
}
exports.allowedTypeFilter = allowedTypeFilter;
/**
 * Converts an ImplicitAnnotatedAllowedTypes to a stored schema.
 * @param schema - The schema to convert.
 * @param options - The options to use for filtering.
 * @returns The converted stored schema.
 */
function convertAllowedTypes(schema, options) {
    const filtered = (0, allowedTypes_js_1.normalizeAnnotatedAllowedTypes)(schema)
        .types.filter((allowedType) => allowedTypeFilter(allowedType, options))
        .map((a) => (0, index_js_1.brand)(a.type.identifier));
    return new Set(filtered);
}
exports.convertAllowedTypes = convertAllowedTypes;
//# sourceMappingURL=toStored.js.map