"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 ClusterModel_exports = {};
__export(ClusterModel_exports, {
  ClusterModel: () => ClusterModel
});
module.exports = __toCommonJS(ClusterModel_exports);
var import_general = require("@matter/general");
var import_Access = require("../aspects/Access.js");
var import_Quality = require("../aspects/Quality.js");
var import_errors = require("../common/errors.js");
var import_common = require("../common/index.js");
var import_elements = require("../elements/index.js");
var import_ClusterRevision = require("../standard/elements/ClusterRevision.js");
var import_FeatureMap = require("../standard/elements/FeatureMap.js");
var import_Aspects = require("./Aspects.js");
var import_AttributeModel = require("./AttributeModel.js");
var import_CommandModel = require("./CommandModel.js");
var import_DatatypeModel = require("./DatatypeModel.js");
var import_EventModel = require("./EventModel.js");
var import_Model = require("./Model.js");
var import_ScopeModel = require("./ScopeModel.js");
/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const QUALITY = Symbol("quality");
class ClusterModel extends import_ScopeModel.ScopeModel {
  tag = import_elements.ClusterElement.Tag;
  get children() {
    return super.children;
  }
  set children(children) {
    super.children = children;
  }
  get diagnostics() {
    return this.effectiveQuality.diagnostics;
  }
  get quality() {
    return import_Aspects.Aspects.getAspect(this, QUALITY, import_Quality.Quality);
  }
  set quality(definition) {
    import_Aspects.Aspects.setAspect(this, QUALITY, import_Quality.Quality, definition);
  }
  get effectiveQuality() {
    return import_Aspects.Aspects.getEffectiveAspect(this, QUALITY, import_Quality.Quality);
  }
  get attributes() {
    return this.all(import_AttributeModel.AttributeModel);
  }
  get commands() {
    return this.all(import_CommandModel.CommandModel);
  }
  get events() {
    return this.all(import_EventModel.EventModel);
  }
  get datatypes() {
    return this.all(import_DatatypeModel.DatatypeModel);
  }
  /**
   * Get attributes, commands and events whether inherited or defined directly in this model.
   */
  get allAces() {
    return this.scope.membersOf(this, { tags: [import_common.ElementTag.Attribute, import_common.ElementTag.Command, import_common.ElementTag.Event] });
  }
  get revision() {
    let revision = 1;
    const revisionAttr = this.get(import_AttributeModel.AttributeModel, import_ClusterRevision.ClusterRevision.id);
    if (typeof revisionAttr?.default === "number") {
      revision = revisionAttr.default;
    }
    return revision;
  }
  get features() {
    return this.featureMap.children ?? [];
  }
  get featureMap() {
    return this.member(import_FeatureMap.FeatureMap.id, [import_common.ElementTag.Attribute]) ?? new import_AttributeModel.AttributeModel(import_FeatureMap.FeatureMap);
  }
  get featureNames() {
    return new import_common.FeatureSet(this.features.map((feature) => feature.name));
  }
  get supportedFeatures() {
    const supported = {};
    for (const feature of this.features) {
      if (feature.default) {
        supported[feature.name] = true;
      }
    }
    return new import_common.FeatureSet(supported);
  }
  set supportedFeatures(features) {
    const featureSet = new import_common.FeatureSet(features);
    let featureMap = this.featureMap;
    if (featureMap.parent !== this) {
      featureMap = featureMap.clone();
      this.children.push(featureMap);
    }
    for (const feature of featureMap.children) {
      const desc = feature.description && (0, import_general.camelize)(feature.description);
      if (desc !== void 0 && featureSet.has(desc)) {
        feature.default = true;
        featureSet.delete(desc);
        continue;
      }
      if (featureSet.has(feature.name)) {
        featureSet.delete(feature.name);
        feature.default = true;
        continue;
      }
      feature.default = void 0;
    }
    if (featureSet.size) {
      throw new import_errors.SchemaImplementationError(
        this,
        `Cannot set unknown feature${featureSet.size > 1 ? "s" : ""} ${(0, import_general.describeList)("and", ...featureSet)}`
      );
    }
  }
  get effectiveMetatype() {
    return import_common.Metatype.object;
  }
  get effectiveAccess() {
    return import_Access.Access.Default;
  }
  valueOf() {
    const result = super.valueOf();
    if (this.quality && !this.quality.empty) {
      result.quality = this.quality.valueOf();
    }
    return result;
  }
  constructor(definition, ...children) {
    super(definition, ...children);
    if (definition instanceof import_Model.Model) {
      import_Aspects.Aspects.cloneAspects(definition, this, QUALITY);
    }
  }
  static Tag = import_elements.ClusterElement.Tag;
  static {
    import_Model.Model.types[this.Tag] = this;
  }
}
//# sourceMappingURL=ClusterModel.js.map
