/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Logger } from "@matter/general";
import { OccupancySensing } from "@matter/types/clusters/occupancy-sensing";
import { OccupancySensingBehavior } from "./OccupancySensingBehavior.js";
const logger = Logger.get("OccupancySensingServer");
const holdTimeDependencies = [
  "holdTimeLimits",
  "pirOccupiedToUnoccupiedDelay",
  "pirUnoccupiedToOccupiedDelay",
  "pirUnoccupiedToOccupiedThreshold",
  "ultrasonicOccupiedToUnoccupiedDelay",
  "ultrasonicUnoccupiedToOccupiedDelay",
  "ultrasonicUnoccupiedToOccupiedThreshold",
  "physicalContactOccupiedToUnoccupiedDelay",
  "physicalContactUnoccupiedToOccupiedDelay",
  "physicalContactUnoccupiedToOccupiedThreshold"
];
class OccupancySensingServer extends OccupancySensingBehavior {
  initialize() {
    if (!Object.values(this.features).some((feature) => feature)) {
      logger.error(
        `OccupancySensingServer: Since revision 5 of the cluster features need to be set based on the detector type. Currently no features are enabled.`
      );
    } else if (!Object.values(this.state.occupancySensorTypeBitmap).some((feature) => feature) || this.state.occupancySensorType === void 0) {
      let adjusted = false;
      if (this.features.passiveInfrared) {
        this.state.occupancySensorTypeBitmap.pir = true;
        adjusted = true;
      }
      if (this.features.ultrasonic) {
        this.state.occupancySensorTypeBitmap.ultrasonic = true;
        adjusted = true;
      }
      if (this.features.physicalContact) {
        this.state.occupancySensorTypeBitmap.physicalContact = true;
        adjusted = true;
      }
      if (adjusted) {
        if (this.state.occupancySensorTypeBitmap.pir) {
          if (this.state.occupancySensorTypeBitmap.ultrasonic) {
            this.state.occupancySensorType = OccupancySensing.OccupancySensorType.PirAndUltrasonic;
          } else {
            this.state.occupancySensorType = OccupancySensing.OccupancySensorType.Pir;
          }
        } else if (this.state.occupancySensorTypeBitmap.physicalContact) {
          this.state.occupancySensorType = OccupancySensing.OccupancySensorType.PhysicalContact;
        }
        logger.debug(
          "Sync occupancySensorType to",
          OccupancySensing.OccupancySensorType[this.state.occupancySensorType],
          "and occupancySensorTypeBitmap to",
          this.state.occupancySensorTypeBitmap,
          "from features",
          this.features
        );
      }
    }
    if (this.state.holdTime === void 0) {
      for (const dep of holdTimeDependencies) {
        if (this.state[dep] !== void 0) {
          this.state[dep] = void 0;
        }
      }
    }
  }
}
export {
  OccupancySensingServer
};
//# sourceMappingURL=OccupancySensingServer.js.map
