"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var MatterModel_exports = {};
__export(MatterModel_exports, {
  MatterModel: () => MatterModel
});
module.exports = __toCommonJS(MatterModel_exports);
var import_ElementTag = require("#common/ElementTag.js");
var import_elements = require("../elements/index.js");
var import_ModelTraversal = require("../logic/ModelTraversal.js");
var import_AttributeModel = require("./AttributeModel.js");
var import_ClusterModel = require("./ClusterModel.js");
var import_DeviceTypeModel = require("./DeviceTypeModel.js");
var import_FabricModel = require("./FabricModel.js");
var import_FieldModel = require("./FieldModel.js");
var import_Globals = require("./Globals.js");
var import_Model = require("./Model.js");
var import_Resource = require("./Resource.js");
var import_ScopeModel = require("./ScopeModel.js");
var import_SemanticNamespaceModel = require("./SemanticNamespaceModel.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class MatterModel extends import_ScopeModel.ScopeModel {
  tag = import_elements.MatterElement.Tag;
  revision;
  #permanentDatatypes;
  #resources;
  /**
   * The default instance of the canonical MatterModel (also exported directly simply as "Matter").
   */
  static standard = new MatterModel({
    name: "Matter",
    children: Object.values(import_Globals.Globals)
  });
  /**
   * Clusters.
   */
  get clusters() {
    return this.all(import_ClusterModel.ClusterModel);
  }
  /**
   * Device types.
   */
  get deviceTypes() {
    return this.all(import_DeviceTypeModel.DeviceTypeModel);
  }
  /**
   * Semantic tag namespaces.
   */
  get semanticNamespaces() {
    return this.all(import_SemanticNamespaceModel.SemanticNamespaceModel);
  }
  /**
   * Global datatypes.
   */
  get datatypes() {
    return this.all(import_FieldModel.FieldModel);
  }
  /**
   * Global attributes.
   */
  get attributes() {
    return this.all(import_AttributeModel.AttributeModel);
  }
  /**
   * Fabrics.
   */
  get fabrics() {
    return this.all(import_FabricModel.FabricModel);
  }
  /**
   * All sub-cluster global elements from this model.
   *
   * This is the set of utility datatypes required by cluster definitions.
   *
   * The returned elements are clones as we use this to initialize empty models for testing or diagnostic purposes.
   */
  get seedGlobals() {
    return this.children.filter((child) => child.isSeed).map((child) => child.clone());
  }
  /**
   * MatterModel always owns itself.
   */
  get root() {
    return this;
  }
  /**
   * The set of "permanent" datatypes.
   *
   * These are datatypes owned by this model with the "isSeed" value set.  For performance reasons we disallow
   * overriding these values.
   */
  get permanentDatatypes() {
    if (this.#permanentDatatypes) {
      return this.#permanentDatatypes;
    }
    this.#permanentDatatypes = Object.fromEntries(
      this.children.filter((model) => model.tag === import_ElementTag.ElementTag.Datatype && model.isSeed).map((model) => [model.name, model])
    );
    this.children.onNameChanged = (name, model) => {
      if (model === void 0) {
        delete this.#permanentDatatypes[name];
      } else {
        this.#permanentDatatypes[model.name] = model;
      }
    };
    return this.#permanentDatatypes;
  }
  /**
   * The resource pool for the node.
   */
  get resources() {
    return this.#resources ?? import_Resource.ResourceBundle.default;
  }
  set resources(resources) {
    this.#resources = resources;
  }
  constructor(definition, ...children) {
    if (definition instanceof import_Model.Model) {
      super(definition, ...children);
      return;
    }
    super(
      {
        name: "Matter",
        children: [],
        ...definition
      },
      ...children
    );
    if (!(definition instanceof import_Model.Model)) {
      this.revision = definition?.revision;
    }
  }
  toElement(omitResources = false, extra) {
    return super.toElement(omitResources, {
      revision: this.revision,
      ...extra
    });
  }
  static Tag = import_elements.MatterElement.Tag;
}
MatterModel.register();
import_ModelTraversal.ModelTraversal.fallbackRoot = MatterModel.standard;
//# sourceMappingURL=MatterModel.js.map
