"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 PowerTopologyServer_exports = {};
__export(PowerTopologyServer_exports, {
  PowerTopologyBaseServer: () => PowerTopologyBaseServer,
  PowerTopologyServer: () => PowerTopologyServer
});
module.exports = __toCommonJS(PowerTopologyServer_exports);
var import_descriptor = require("#behaviors/descriptor");
var import_electrical_energy_measurement = require("#behaviors/electrical-energy-measurement");
var import_electrical_power_measurement = require("#behaviors/electrical-power-measurement");
var import_power_topology = require("#clusters/power-topology");
var import_general = require("#general");
var import_types = require("#types");
var import_PowerTopologyBehavior = require("./PowerTopologyBehavior.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const PowerTopologyBase = import_PowerTopologyBehavior.PowerTopologyBehavior.with(
  import_power_topology.PowerTopology.Feature.SetTopology,
  import_power_topology.PowerTopology.Feature.DynamicPowerFlow
);
class PowerTopologyBaseServer extends PowerTopologyBase {
  async initialize() {
    if (this.agent.has(import_electrical_power_measurement.ElectricalPowerMeasurementBehavior) || this.agent.has(import_electrical_energy_measurement.ElectricalEnergyMeasurementBehavior)) {
      (await this.agent.load(import_descriptor.DescriptorServer)).addDeviceTypes("ElectricalSensor");
    }
    if (this.state.activeEndpoints !== void 0) {
      this.#assertActiveEndpointsAllowed(this.state.activeEndpoints);
      this.reactTo(this.events.activeEndpoints$Changing, this.#assertActiveEndpointsAllowed);
    }
  }
  #assertActiveEndpointsAllowed(list) {
    const availableEndpoints = this.state.availableEndpoints;
    list.forEach((endpoint) => {
      if (!availableEndpoints.includes(endpoint)) {
        throw new import_general.ImplementationError(`Endpoint ${endpoint} is not in the list of available endpoints`);
      }
    });
  }
}
class PowerTopologyServer extends PowerTopologyBaseServer.for((0, import_types.ClusterType)(import_power_topology.PowerTopology.Base)) {
}
//# sourceMappingURL=PowerTopologyServer.js.map
