/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { DatatypeModel } from "#models/DatatypeModel.js";
import { ImplementationError } from "@matter/general";
import { MissingMetadataError } from "../decoration/errors.js";
import { Semantics } from "../decoration/semantics/Semantics.js";
function Schema(source) {
  let model;
  if ("tag" in source) {
    source.finalize();
    model = source;
  } else {
    const semantics = Semantics.classOf(source);
    semantics.finalize();
    model = semantics.semanticModel;
  }
  if (!model) {
    return;
  }
  if (model.tag !== "cluster" && !model.isType) {
    throw new ImplementationError(`Model ${model.name} tag ${model.tag} is not legal for schema`);
  }
  return model;
}
((Schema2) => {
  function Required(source) {
    const schema = Schema2(source);
    if (schema === void 0) {
      throw new MissingMetadataError(`Metadata missing for class ${source.name}`);
    }
    return schema;
  }
  Schema2.Required = Required;
  Schema2.empty = new DatatypeModel({ name: "Empty", type: "struct" });
  Schema2.empty.finalize();
})(Schema || (Schema = {}));
export {
  Schema
};
//# sourceMappingURL=Schema.js.map
