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