/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { brand } from "../../util/index.js";
import { normalizeAnnotatedAllowedTypes, } from "./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.
 */
export 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;
}
/**
 * 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.
 */
export function convertAllowedTypes(schema, options) {
    const filtered = normalizeAnnotatedAllowedTypes(schema)
        .types.filter((allowedType) => allowedTypeFilter(allowedType, options))
        .map((a) => brand(a.type.identifier));
    return new Set(filtered);
}
//# sourceMappingURL=toStored.js.map