/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { MutableCluster } from "../cluster/mutation/MutableCluster.js";
import { FixedAttribute, Attribute } from "../cluster/Cluster.js";
import { TlvArray } from "../tlv/TlvArray.js";
import { TlvEndpointNumber } from "../datatype/EndpointNumber.js";
import { BitFlag } from "../schema/BitmapSchema.js";
import { ClusterRegistry } from "../cluster/ClusterRegistry.js";
var PowerTopology;
((PowerTopology2) => {
  let Feature;
  ((Feature2) => {
    Feature2["NodeTopology"] = "NodeTopology";
    Feature2["TreeTopology"] = "TreeTopology";
    Feature2["SetTopology"] = "SetTopology";
    Feature2["DynamicPowerFlow"] = "DynamicPowerFlow";
  })(Feature = PowerTopology2.Feature || (PowerTopology2.Feature = {}));
  PowerTopology2.SetTopologyComponent = MutableCluster.Component({
    attributes: {
      /**
       * Indicates the list of endpoints capable of providing power to and/or consuming power from the endpoint
       * hosting this server.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.8.5.1
       */
      availableEndpoints: FixedAttribute(0, TlvArray(TlvEndpointNumber, { maxLength: 20 }), { default: [] })
    }
  });
  PowerTopology2.DynamicPowerFlowComponent = MutableCluster.Component({
    attributes: {
      /**
       * Indicates the current list of endpoints currently providing or consuming power to or from the endpoint
       * hosting this server. This list shall be a subset of the value of the AvailableEndpoints attribute.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.8.5.2
       */
      activeEndpoints: Attribute(
        1,
        TlvArray(TlvEndpointNumber, { maxLength: 20 }),
        { persistent: true, default: [] }
      )
    }
  });
  PowerTopology2.Base = MutableCluster.Component({
    id: 156,
    name: "PowerTopology",
    revision: 1,
    features: {
      /**
       * This endpoint provides or consumes power to/from the entire node
       */
      nodeTopology: BitFlag(0),
      /**
       * This endpoint provides or consumes power to/from itself and its child endpoints
       */
      treeTopology: BitFlag(1),
      /**
       * This endpoint provides or consumes power to/from a specified set of endpoints
       */
      setTopology: BitFlag(2),
      /**
       * The specified set of endpoints may change
       */
      dynamicPowerFlow: BitFlag(3)
    },
    /**
     * This metadata controls which PowerTopologyCluster elements matter.js activates for specific feature
     * combinations.
     */
    extensions: MutableCluster.Extensions(
      { flags: { setTopology: true }, component: PowerTopology2.SetTopologyComponent },
      { flags: { dynamicPowerFlow: true }, component: PowerTopology2.DynamicPowerFlowComponent },
      { flags: { dynamicPowerFlow: true, setTopology: false }, component: false },
      { flags: { nodeTopology: true, treeTopology: true }, component: false },
      { flags: { nodeTopology: true, setTopology: true }, component: false },
      { flags: { treeTopology: true, setTopology: true }, component: false },
      { flags: { nodeTopology: false, treeTopology: false, setTopology: false }, component: false }
    )
  });
  PowerTopology2.ClusterInstance = MutableCluster.ExtensibleOnly(PowerTopology2.Base);
  PowerTopology2.Cluster = PowerTopology2.ClusterInstance;
  const SET = { setTopology: true };
  const DYPF = { dynamicPowerFlow: true };
  PowerTopology2.CompleteInstance = MutableCluster({
    id: PowerTopology2.Base.id,
    name: PowerTopology2.Base.name,
    revision: PowerTopology2.Base.revision,
    features: PowerTopology2.Base.features,
    attributes: {
      availableEndpoints: MutableCluster.AsConditional(
        PowerTopology2.SetTopologyComponent.attributes.availableEndpoints,
        { mandatoryIf: [SET] }
      ),
      activeEndpoints: MutableCluster.AsConditional(
        PowerTopology2.DynamicPowerFlowComponent.attributes.activeEndpoints,
        { mandatoryIf: [DYPF] }
      )
    }
  });
  PowerTopology2.Complete = PowerTopology2.CompleteInstance;
})(PowerTopology || (PowerTopology = {}));
const PowerTopologyCluster = PowerTopology.Cluster;
ClusterRegistry.register(PowerTopology.Complete);
export {
  PowerTopology,
  PowerTopologyCluster
};
//# sourceMappingURL=power-topology.js.map
