/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { ClusterType } from "@matter/types";
import { ElectricalEnergyMeasurement } from "@matter/types/clusters/electrical-energy-measurement";
import { ElectricalEnergyMeasurementBehavior } from "./ElectricalEnergyMeasurementBehavior.js";
const ElectricalEnergyMeasurementBase = ElectricalEnergyMeasurementBehavior.for(
  ElectricalEnergyMeasurement.Complete
).with(
  ElectricalEnergyMeasurement.Feature.CumulativeEnergy,
  ElectricalEnergyMeasurement.Feature.PeriodicEnergy,
  ElectricalEnergyMeasurement.Feature.ImportedEnergy,
  ElectricalEnergyMeasurement.Feature.ExportedEnergy
);
class ElectricalEnergyMeasurementBaseServer extends ElectricalEnergyMeasurementBase {
  /**
   * Convenience method to set the measurement values for the cluster in an atomic way. This method updates the
   * attributes with the provided data and also sends the events for the imported and exported energy values.
   */
  setMeasurement(measurement) {
    if (this.features.cumulativeEnergy) {
      const useImported = measurement.cumulativeEnergy?.imported !== void 0 && this.features.importedEnergy;
      const useExported = measurement.cumulativeEnergy?.exported !== void 0 && this.features.exportedEnergy;
      if (useImported) {
        this.state.cumulativeEnergyImported = measurement.cumulativeEnergy.imported;
      }
      if (useExported) {
        this.state.cumulativeEnergyExported = measurement.cumulativeEnergy.exported;
      }
      if (useImported || useExported) {
        this.events.cumulativeEnergyMeasured?.emit(
          {
            energyImported: measurement.cumulativeEnergy?.imported,
            energyExported: measurement.cumulativeEnergy?.exported
          },
          this.context
        );
      }
    }
    if (this.features.periodicEnergy) {
      const useImported = measurement.periodicEnergy?.imported !== void 0 && this.features.importedEnergy;
      const useExported = measurement.periodicEnergy?.exported !== void 0 && this.features.exportedEnergy;
      if (useImported) {
        this.state.periodicEnergyImported = measurement.periodicEnergy.imported;
      }
      if (useExported) {
        this.state.periodicEnergyExported = measurement.periodicEnergy.exported;
      }
      if (useImported || useExported) {
        this.events.periodicEnergyMeasured?.emit(
          {
            energyImported: measurement.periodicEnergy?.imported,
            energyExported: measurement.periodicEnergy?.exported
          },
          this.context
        );
      }
    }
  }
}
((ElectricalEnergyMeasurementBaseServer2) => {
})(ElectricalEnergyMeasurementBaseServer || (ElectricalEnergyMeasurementBaseServer = {}));
class ElectricalEnergyMeasurementServer extends ElectricalEnergyMeasurementBaseServer.for(
  ClusterType(ElectricalEnergyMeasurement.Base)
) {
}
export {
  ElectricalEnergyMeasurementBaseServer,
  ElectricalEnergyMeasurementServer
};
//# sourceMappingURL=ElectricalEnergyMeasurementServer.js.map
