/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { DescriptorServer } from "#behaviors/descriptor";
import { ElectricalEnergyMeasurementBehavior } from "#behaviors/electrical-energy-measurement";
import { ElectricalPowerMeasurementBehavior } from "#behaviors/electrical-power-measurement";
import { ImplementationError } from "@matter/general";
import { PowerTopology } from "@matter/types/clusters/power-topology";
import { PowerTopologyBehavior } from "./PowerTopologyBehavior.js";
const PowerTopologyBase = PowerTopologyBehavior.with(
  PowerTopology.Feature.SetTopology,
  PowerTopology.Feature.DynamicPowerFlow
);
class PowerTopologyBaseServer extends PowerTopologyBase {
  async initialize() {
    if (this.agent.has(ElectricalPowerMeasurementBehavior) || this.agent.has(ElectricalEnergyMeasurementBehavior)) {
      (await this.agent.load(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 ImplementationError(`Endpoint ${endpoint} is not in the list of available endpoints`);
      }
    });
  }
}
class PowerTopologyServer extends PowerTopologyBaseServer.for(PowerTopology) {
}
export {
  PowerTopologyBaseServer,
  PowerTopologyServer
};
//# sourceMappingURL=PowerTopologyServer.js.map
