"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 PhysicalDeviceProperties_exports = {};
__export(PhysicalDeviceProperties_exports, {
  PhysicalDeviceProperties: () => PhysicalDeviceProperties
});
module.exports = __toCommonJS(PhysicalDeviceProperties_exports);
var import_general = require("@matter/general");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const logger = import_general.Logger.get("PhysicalDeviceProperties");
const DEFAULT_SUBSCRIPTION_FLOOR_DEFAULT = (0, import_general.Seconds)(1);
const DEFAULT_SUBSCRIPTION_FLOOR_ICD = import_general.Instant;
const DEFAULT_SUBSCRIPTION_CEILING_WIFI = (0, import_general.Minutes)(1);
const DEFAULT_SUBSCRIPTION_CEILING_THREAD = (0, import_general.Minutes)(1);
const DEFAULT_SUBSCRIPTION_CEILING_THREAD_SLEEPY = (0, import_general.Minutes)(3);
const DEFAULT_SUBSCRIPTION_CEILING_BATTERY_POWERED = (0, import_general.Minutes)(10);
const THREAD_SUBSCRIPTION_CEILING_JITTER = 0.05;
var PhysicalDeviceProperties;
((PhysicalDeviceProperties2) => {
  function subscriptionIntervalBoundsFor(options) {
    const { properties, request } = options ?? {};
    let { description } = options ?? {};
    let minIntervalFloor, maxIntervalCeiling;
    if (request) {
      ({ minIntervalFloor, maxIntervalCeiling } = request);
    }
    if (description === void 0) {
      description = "Node";
    }
    const {
      isMainsPowered,
      isBatteryPowered,
      isIntermittentlyConnected,
      supportsThread,
      isThreadSleepyEndDevice,
      threadActive
    } = properties ?? {};
    if (isIntermittentlyConnected && minIntervalFloor !== DEFAULT_SUBSCRIPTION_FLOOR_ICD) {
      if (minIntervalFloor !== void 0) {
        logger.info(
          `${description}: Overwriting minIntervalFloorSeconds for intermittently connected device to ${import_general.Duration.format(DEFAULT_SUBSCRIPTION_FLOOR_ICD)}`
        );
      }
      minIntervalFloor = DEFAULT_SUBSCRIPTION_FLOOR_ICD;
    }
    if (minIntervalFloor === void 0) {
      minIntervalFloor = DEFAULT_SUBSCRIPTION_FLOOR_DEFAULT;
    }
    const defaultCeiling = isBatteryPowered && !isMainsPowered ? DEFAULT_SUBSCRIPTION_CEILING_BATTERY_POWERED : isThreadSleepyEndDevice ? DEFAULT_SUBSCRIPTION_CEILING_THREAD_SLEEPY : supportsThread ? DEFAULT_SUBSCRIPTION_CEILING_THREAD : DEFAULT_SUBSCRIPTION_CEILING_WIFI;
    if (maxIntervalCeiling === void 0) {
      maxIntervalCeiling = defaultCeiling;
    }
    if (maxIntervalCeiling < defaultCeiling) {
      logger.debug(
        `${description}: maxIntervalCeilingSeconds ideally is ${import_general.Duration.format(defaultCeiling)} instead of ${import_general.Duration.format(maxIntervalCeiling)} due to device type`
      );
    }
    if (threadActive) {
      const maxJitter = maxIntervalCeiling * THREAD_SUBSCRIPTION_CEILING_JITTER;
      const jitter = Math.round(maxJitter * Math.random() * 2 - maxJitter);
      maxIntervalCeiling = (0, import_general.Seconds)(import_general.Seconds.of((0, import_general.Millis)(maxIntervalCeiling + jitter)));
    }
    return {
      minIntervalFloor,
      maxIntervalCeiling
    };
  }
  PhysicalDeviceProperties2.subscriptionIntervalBoundsFor = subscriptionIntervalBoundsFor;
})(PhysicalDeviceProperties || (PhysicalDeviceProperties = {}));
//# sourceMappingURL=PhysicalDeviceProperties.js.map
