/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { isFluidHandle } from "@fluidframework/runtime-utils/internal";
import { assert, unreachableCase } from "@fluidframework/core-utils/internal";
import { ValueSchema } from "../core/index.js";
export function allowsValue(schema, nodeValue) {
    if (schema === undefined) {
        return nodeValue === undefined;
    }
    return valueSchemaAllows(schema, nodeValue);
}
export function valueSchemaAllows(schema, nodeValue) {
    switch (schema) {
        case ValueSchema.String:
            return typeof nodeValue === "string";
        case ValueSchema.Number:
            return typeof nodeValue === "number";
        case ValueSchema.Boolean:
            return typeof nodeValue === "boolean";
        case ValueSchema.FluidHandle:
            return isFluidHandle(nodeValue);
        case ValueSchema.Null:
            return nodeValue === null;
        default:
            unreachableCase(schema);
    }
}
export function assertAllowedValue(value) {
    assert(isTreeValue(value), 0x843 /* invalid value */);
}
/**
 * Checks if a value is a {@link TreeValue}.
 */
export function isTreeValue(nodeValue) {
    switch (typeof nodeValue) {
        case "string":
        case "number":
        case "boolean":
            return true;
        default:
            return nodeValue === null || isFluidHandle(nodeValue);
    }
}
//# sourceMappingURL=valueUtilities.js.map