/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { strict as assert } from "assert";
import { jsonArray, jsonObject, jsonSchema, leaf } from "../../../domains/index.js";
import { Any, FlexFieldSchema, allowedTypesIsAny, schemaIsFieldNode, schemaIsLeaf, schemaIsMap, schemaIsObjectNode,
// eslint-disable-next-line import/no-internal-modules
 } from "../../../feature-libraries/typed-schema/typedTreeSchema.js";
import { FieldKinds, SchemaBuilderBase } from "../../../feature-libraries/index.js";
describe("typedTreeSchema", () => {
    const builder = new SchemaBuilderBase(FieldKinds.optional, {
        scope: "test",
        libraries: [jsonSchema],
    });
    const emptyObjectSchema = builder.object("empty", {});
    const basicObjectSchema = builder.object("basicObject", { foo: Any });
    const basicFieldNode = builder.fieldNode("field", Any);
    // TODO: once schema kinds are separated, test object with EmptyKey.
    const recursiveObject = builder.objectRecursive("recursiveObject", {
        foo: FlexFieldSchema.createUnsafe(FieldKinds.optional, [() => recursiveObject]),
    });
    it("schema is", () => {
        assert(schemaIsLeaf(leaf.boolean));
        assert(!schemaIsFieldNode(leaf.boolean));
        assert(!schemaIsObjectNode(leaf.boolean));
        assert(!schemaIsMap(leaf.boolean));
        assert(!schemaIsLeaf(jsonArray));
        assert(schemaIsFieldNode(jsonArray));
        assert(!schemaIsObjectNode(jsonArray));
        assert(!schemaIsMap(jsonArray));
        assert(!schemaIsLeaf(jsonObject));
        assert(!schemaIsFieldNode(jsonObject));
        assert(!schemaIsObjectNode(jsonObject));
        assert(schemaIsMap(jsonObject));
        assert(!schemaIsLeaf(emptyObjectSchema));
        assert(!schemaIsFieldNode(emptyObjectSchema));
        assert(schemaIsObjectNode(emptyObjectSchema));
        assert(!schemaIsMap(emptyObjectSchema));
        assert(!schemaIsLeaf(basicObjectSchema));
        assert(!schemaIsFieldNode(basicObjectSchema));
        assert(schemaIsObjectNode(basicObjectSchema));
        assert(!schemaIsMap(basicObjectSchema));
        assert(!schemaIsLeaf(recursiveObject));
        assert(!schemaIsFieldNode(recursiveObject));
        assert(schemaIsObjectNode(recursiveObject));
        assert(!schemaIsMap(recursiveObject));
    });
    describe("TreeFieldSchema", () => {
        it("types - any", () => {
            const schema = FlexFieldSchema.create(FieldKinds.optional, [Any]);
            assert(allowedTypesIsAny(schema.allowedTypes));
            assert.equal(schema.allowedTypeSet, Any);
            assert.equal(schema.types, undefined);
        });
        it("types - single", () => {
            const schema = FlexFieldSchema.create(FieldKinds.optional, [leaf.number]);
            assert(!allowedTypesIsAny(schema.allowedTypes));
            assert.deepEqual(schema.allowedTypes, [leaf.number]);
            assert.deepEqual(schema.allowedTypeSet, new Set([leaf.number]));
            assert.deepEqual(schema.types, new Set([leaf.number.name]));
        });
        it("types - lazy", () => {
            const schema = FlexFieldSchema.create(FieldKinds.optional, [() => leaf.number]);
            assert(!allowedTypesIsAny(schema.allowedTypes));
            assert.deepEqual(schema.allowedTypeSet, new Set([leaf.number]));
            assert.deepEqual(schema.types, new Set([leaf.number.name]));
        });
    });
    {
    }
    {
    }
    {
        // TODO: Fix
        // type _4 = requireFalse<isAssignableTo<typeof jsonArray, ObjectNodeSchema>>
    }
    {
    }
    {
    }
});
//# sourceMappingURL=typedTreeSchema.spec.js.map