"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 OccupancySensingServer_exports = {};
__export(OccupancySensingServer_exports, {
  OccupancySensingServer: () => OccupancySensingServer
});
module.exports = __toCommonJS(OccupancySensingServer_exports);
var import_general = require("@matter/general");
var import_occupancy_sensing = require("@matter/types/clusters/occupancy-sensing");
var import_OccupancySensingBehavior = require("./OccupancySensingBehavior.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const logger = import_general.Logger.get("OccupancySensingServer");
class OccupancySensingServer extends import_OccupancySensingBehavior.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 = import_occupancy_sensing.OccupancySensing.OccupancySensorType.PirAndUltrasonic;
          } else {
            this.state.occupancySensorType = import_occupancy_sensing.OccupancySensing.OccupancySensorType.Pir;
          }
        } else if (this.state.occupancySensorTypeBitmap.physicalContact) {
          this.state.occupancySensorType = import_occupancy_sensing.OccupancySensing.OccupancySensorType.PhysicalContact;
        }
        logger.debug(
          "Sync occupancySensorType to",
          import_occupancy_sensing.OccupancySensing.OccupancySensorType[this.state.occupancySensorType],
          "and occupancySensorTypeBitmap to",
          this.state.occupancySensorTypeBitmap,
          "from features",
          this.features
        );
      }
    }
    if (this.state.holdTime === void 0) {
      const state = this.state;
      for (const dep of holdTimeDependencies) {
        if (state[dep] !== void 0) {
          state[dep] = void 0;
        }
      }
    }
  }
}
const holdTimeDependencies = [
  "holdTimeLimits",
  "pirOccupiedToUnoccupiedDelay",
  "pirUnoccupiedToOccupiedDelay",
  "pirUnoccupiedToOccupiedThreshold",
  "ultrasonicOccupiedToUnoccupiedDelay",
  "ultrasonicUnoccupiedToOccupiedDelay",
  "ultrasonicUnoccupiedToOccupiedThreshold",
  "physicalContactOccupiedToUnoccupiedDelay",
  "physicalContactUnoccupiedToOccupiedDelay",
  "physicalContactUnoccupiedToOccupiedThreshold"
];
//# sourceMappingURL=OccupancySensingServer.js.map
