/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Duration, Instant, Logger, Millis, Minutes, Seconds } from "@matter/general";
const logger = Logger.get("PhysicalDeviceProperties");
const DEFAULT_SUBSCRIPTION_FLOOR_DEFAULT = Seconds(1);
const DEFAULT_SUBSCRIPTION_FLOOR_ICD = Instant;
const DEFAULT_SUBSCRIPTION_CEILING_WIFI = Minutes(1);
const DEFAULT_SUBSCRIPTION_CEILING_THREAD = Minutes(1);
const DEFAULT_SUBSCRIPTION_CEILING_THREAD_SLEEPY = Minutes(3);
const DEFAULT_SUBSCRIPTION_CEILING_BATTERY_POWERED = Minutes(10);
const SUBSCRIPTION_CEILING_JITTER = 0.1;
const SUBSCRIPTION_CEILING_JITTER_MIN = Seconds(10);
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 } = properties ?? {};
    if (isIntermittentlyConnected && minIntervalFloor !== DEFAULT_SUBSCRIPTION_FLOOR_ICD) {
      if (minIntervalFloor !== void 0) {
        logger.info(
          `${description}: Overwriting minIntervalFloorSeconds for intermittently connected device to ${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 ${Duration.format(defaultCeiling)} instead of ${Duration.format(maxIntervalCeiling)} due to device type`
      );
    }
    const maxJitter = Math.max(maxIntervalCeiling * SUBSCRIPTION_CEILING_JITTER, SUBSCRIPTION_CEILING_JITTER_MIN);
    const jitter = Math.round(maxJitter * Math.random());
    maxIntervalCeiling = Duration.max(minIntervalFloor, Seconds(Seconds.of(Millis(maxIntervalCeiling + jitter))));
    return {
      minIntervalFloor,
      maxIntervalCeiling
    };
  }
  PhysicalDeviceProperties2.subscriptionIntervalBoundsFor = subscriptionIntervalBoundsFor;
})(PhysicalDeviceProperties || (PhysicalDeviceProperties = {}));
export {
  PhysicalDeviceProperties
};
//# sourceMappingURL=PhysicalDeviceProperties.js.map
