"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 ElectricalEnergyMeasurementServer_exports = {};
__export(ElectricalEnergyMeasurementServer_exports, {
  ElectricalEnergyMeasurementBaseServer: () => ElectricalEnergyMeasurementBaseServer,
  ElectricalEnergyMeasurementServer: () => ElectricalEnergyMeasurementServer
});
module.exports = __toCommonJS(ElectricalEnergyMeasurementServer_exports);
var import_electrical_energy_measurement = require("@matter/types/clusters/electrical-energy-measurement");
var import_ElectricalEnergyMeasurementBehavior = require("./ElectricalEnergyMeasurementBehavior.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const ElectricalEnergyMeasurementBase = import_ElectricalEnergyMeasurementBehavior.ElectricalEnergyMeasurementBehavior.with(
  import_electrical_energy_measurement.ElectricalEnergyMeasurement.Feature.CumulativeEnergy,
  import_electrical_energy_measurement.ElectricalEnergyMeasurement.Feature.PeriodicEnergy,
  import_electrical_energy_measurement.ElectricalEnergyMeasurement.Feature.ImportedEnergy,
  import_electrical_energy_measurement.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 ?? null;
      }
      if (useExported) {
        this.state.cumulativeEnergyExported = measurement.cumulativeEnergy.exported ?? null;
      }
      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 ?? null;
      }
      if (useExported) {
        this.state.periodicEnergyExported = measurement.periodicEnergy.exported ?? null;
      }
      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(
  import_electrical_energy_measurement.ElectricalEnergyMeasurement
) {
}
//# sourceMappingURL=ElectricalEnergyMeasurementServer.js.map
