var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
var __typeError = (msg) => {
  throw TypeError(msg);
};
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
var __runInitializers = (array, flags, self, value) => {
  for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
  return value;
};
var __decorateElement = (array, flags, name, decorators, target, extra) => {
  var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
  var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
  var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
  var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
    return __privateGet(this, extra);
  }, set [name](x) {
    return __privateSet(this, extra, x);
  } }, name));
  k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
  for (var i = decorators.length - 1; i >= 0; i--) {
    ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
    if (k) {
      ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
      if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
      if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
    }
    it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
    if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
    else if (typeof it !== "object" || it === null) __typeError("Object expected");
    else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
  }
  return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
};
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Logger, Minutes } from "@matter/general";
import { duration, field, uint16 } from "@matter/model";
import { Ble, FabricManager } from "@matter/protocol";
import { CommissioningServer } from "../commissioning/CommissioningServer.js";
import { NetworkBehavior } from "./NetworkBehavior.js";
const logger = Logger.get("NetworkingServer");
class NetworkServer extends NetworkBehavior {
  initialize() {
    if (this.state.ble === void 0) {
      this.state.ble = this.env.has(Ble);
    } else if (this.state.ble && !this.env.has(Ble)) {
      logger.warn("Disabling Bluetooth commissioning because BLE support is not installed");
      this.state.ble = false;
    }
    const discoveryCaps = this.state.discoveryCapabilities;
    switch (discoveryCaps.ble) {
      case void 0:
        discoveryCaps.ble = this.state.ble;
        break;
      case true:
        if (!this.state.ble) {
          discoveryCaps.ble = false;
        }
        break;
    }
    if (discoveryCaps.onIpNetwork === void 0) {
      discoveryCaps.onIpNetwork = true;
    }
    this.reactTo(this.endpoint.eventsOf(CommissioningServer).commissioned, this.#endUncommissionedMode);
    if (discoveryCaps.ble) {
      this.reactTo(this.env.get(FabricManager).events.added, this.#ensureMdnsAdvertiser);
    }
    return super.initialize();
  }
  #endUncommissionedMode() {
    if (this.internal.runtime) {
      this.internal.runtime.endUncommissionedMode();
    }
  }
  #ensureMdnsAdvertiser() {
    if (this.internal.runtime) {
      this.internal.runtime.ensureMdnsAdvertiser();
    }
  }
}
((NetworkServer2) => {
  var _minimumTimeBetweenMrpKicks_dec, _delayAfterUnhandledError_dec, _delayAfterPeerError_dec, _delayAfterNetworkError_dec, _delayBeforeNextAddress_dec, _maxDelayBetweenInitialContactRetries_dec, _defaultConnectionTimeout_dec, _init, _additionalMrpDelay_dec, _timeout_dec, _delay_dec, _exchanges_dec, _init2, _probeAddress_dec, _connect_dec, _a, _init3, _icdLit_dec, _unlimited_dec, _unknown_dec, _conservative_dec, _thread_dec, _wifi_dec, _fast_dec, _init4, _clientCacheFlushInterval_dec, _profiles_dec, _timing_dec, _b, _init5;
  class Internal extends NetworkBehavior.Internal {
  }
  NetworkServer2.Internal = Internal;
  _defaultConnectionTimeout_dec = [field(duration)], _maxDelayBetweenInitialContactRetries_dec = [field(duration)], _delayBeforeNextAddress_dec = [field(duration)], _delayAfterNetworkError_dec = [field(duration)], _delayAfterPeerError_dec = [field(duration)], _delayAfterUnhandledError_dec = [field(duration)], _minimumTimeBetweenMrpKicks_dec = [field(duration)];
  class TimingConfig {
    constructor() {
      __publicField(this, "defaultConnectionTimeout", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
      __publicField(this, "maxDelayBetweenInitialContactRetries", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
      __publicField(this, "delayBeforeNextAddress", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
      __publicField(this, "delayAfterNetworkError", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
      __publicField(this, "delayAfterPeerError", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
      __publicField(this, "delayAfterUnhandledError", __runInitializers(_init, 28, this)), __runInitializers(_init, 31, this);
      __publicField(this, "minimumTimeBetweenMrpKicks", __runInitializers(_init, 32, this)), __runInitializers(_init, 35, this);
    }
  }
  _init = __decoratorStart(null);
  __decorateElement(_init, 5, "defaultConnectionTimeout", _defaultConnectionTimeout_dec, TimingConfig);
  __decorateElement(_init, 5, "maxDelayBetweenInitialContactRetries", _maxDelayBetweenInitialContactRetries_dec, TimingConfig);
  __decorateElement(_init, 5, "delayBeforeNextAddress", _delayBeforeNextAddress_dec, TimingConfig);
  __decorateElement(_init, 5, "delayAfterNetworkError", _delayAfterNetworkError_dec, TimingConfig);
  __decorateElement(_init, 5, "delayAfterPeerError", _delayAfterPeerError_dec, TimingConfig);
  __decorateElement(_init, 5, "delayAfterUnhandledError", _delayAfterUnhandledError_dec, TimingConfig);
  __decorateElement(_init, 5, "minimumTimeBetweenMrpKicks", _minimumTimeBetweenMrpKicks_dec, TimingConfig);
  __decoratorMetadata(_init, TimingConfig);
  NetworkServer2.TimingConfig = TimingConfig;
  _exchanges_dec = [field(uint16)], _delay_dec = [field(duration)], _timeout_dec = [field(duration)], _additionalMrpDelay_dec = [field(duration)];
  class ConcreteLimitsConfig {
    constructor() {
      __publicField(this, "exchanges", __runInitializers(_init2, 8, this)), __runInitializers(_init2, 11, this);
      __publicField(this, "delay", __runInitializers(_init2, 12, this)), __runInitializers(_init2, 15, this);
      __publicField(this, "timeout", __runInitializers(_init2, 16, this)), __runInitializers(_init2, 19, this);
      __publicField(this, "additionalMrpDelay", __runInitializers(_init2, 20, this)), __runInitializers(_init2, 23, this);
    }
  }
  _init2 = __decoratorStart(null);
  __decorateElement(_init2, 5, "exchanges", _exchanges_dec, ConcreteLimitsConfig);
  __decorateElement(_init2, 5, "delay", _delay_dec, ConcreteLimitsConfig);
  __decorateElement(_init2, 5, "timeout", _timeout_dec, ConcreteLimitsConfig);
  __decorateElement(_init2, 5, "additionalMrpDelay", _additionalMrpDelay_dec, ConcreteLimitsConfig);
  __decoratorMetadata(_init2, ConcreteLimitsConfig);
  NetworkServer2.ConcreteLimitsConfig = ConcreteLimitsConfig;
  class LimitsConfig extends (_a = ConcreteLimitsConfig, _connect_dec = [field(ConcreteLimitsConfig)], _probeAddress_dec = [field(ConcreteLimitsConfig)], _a) {
    constructor() {
      super(...arguments);
      __publicField(this, "connect", __runInitializers(_init3, 8, this)), __runInitializers(_init3, 11, this);
      __publicField(this, "probeAddress", __runInitializers(_init3, 12, this)), __runInitializers(_init3, 15, this);
    }
  }
  _init3 = __decoratorStart(_a);
  __decorateElement(_init3, 5, "connect", _connect_dec, LimitsConfig);
  __decorateElement(_init3, 5, "probeAddress", _probeAddress_dec, LimitsConfig);
  __decoratorMetadata(_init3, LimitsConfig);
  NetworkServer2.LimitsConfig = LimitsConfig;
  _fast_dec = [field(LimitsConfig)], _wifi_dec = [field(LimitsConfig)], _thread_dec = [field(LimitsConfig)], _conservative_dec = [field(LimitsConfig)], _unknown_dec = [field(LimitsConfig)], _unlimited_dec = [field(LimitsConfig)], _icdLit_dec = [field(LimitsConfig)];
  class ProfilesConfig {
    constructor() {
      __publicField(this, "fast", __runInitializers(_init4, 8, this)), __runInitializers(_init4, 11, this);
      __publicField(this, "wifi", __runInitializers(_init4, 12, this)), __runInitializers(_init4, 15, this);
      __publicField(this, "thread", __runInitializers(_init4, 16, this)), __runInitializers(_init4, 19, this);
      __publicField(this, "conservative", __runInitializers(_init4, 20, this)), __runInitializers(_init4, 23, this);
      __publicField(this, "unknown", __runInitializers(_init4, 24, this)), __runInitializers(_init4, 27, this);
      __publicField(this, "unlimited", __runInitializers(_init4, 28, this)), __runInitializers(_init4, 31, this);
      __publicField(this, "icdLit", __runInitializers(_init4, 32, this)), __runInitializers(_init4, 35, this);
    }
  }
  _init4 = __decoratorStart(null);
  __decorateElement(_init4, 5, "fast", _fast_dec, ProfilesConfig);
  __decorateElement(_init4, 5, "wifi", _wifi_dec, ProfilesConfig);
  __decorateElement(_init4, 5, "thread", _thread_dec, ProfilesConfig);
  __decorateElement(_init4, 5, "conservative", _conservative_dec, ProfilesConfig);
  __decorateElement(_init4, 5, "unknown", _unknown_dec, ProfilesConfig);
  __decorateElement(_init4, 5, "unlimited", _unlimited_dec, ProfilesConfig);
  __decorateElement(_init4, 5, "icdLit", _icdLit_dec, ProfilesConfig);
  __decoratorMetadata(_init4, ProfilesConfig);
  NetworkServer2.ProfilesConfig = ProfilesConfig;
  class State extends (_b = NetworkBehavior.State, _timing_dec = [field(TimingConfig)], _profiles_dec = [field(ProfilesConfig)], _clientCacheFlushInterval_dec = [field(duration)], _b) {
    constructor() {
      super(...arguments);
      __publicField(this, "listeningAddressIpv4");
      __publicField(this, "listeningAddressIpv6");
      __publicField(this, "ipv4", true);
      __publicField(this, "ble");
      __publicField(this, "discoveryCapabilities", {
        onIpNetwork: true
      });
      __publicField(this, "subscriptionOptions");
      /**
       * Enable TCP transport. `true` enables both incoming (server) and outgoing (client).
       * Fine-grained control via `{ incoming?: boolean; outgoing?: boolean }`.
       * Disabled by default.
       */
      __publicField(this, "tcp");
      /**
       * Preferred transport for outgoing connections. Defaults to UDP when not set.
       */
      __publicField(this, "transportPreference");
      /**
       * Network profile describing our own (local) network — the sender-side MRP additive-delay
       * axis.  Defaults to "fast"; set to "thread" on a Thread device.
       */
      __publicField(this, "ownNetworkProfileId", "fast");
      __publicField(this, "timing", __runInitializers(_init5, 8, this)), __runInitializers(_init5, 11, this);
      __publicField(this, "profiles", __runInitializers(_init5, 12, this)), __runInitializers(_init5, 15, this);
      __publicField(this, "clientCacheFlushInterval", __runInitializers(_init5, 16, this, Minutes(20))), __runInitializers(_init5, 19, this);
    }
  }
  _init5 = __decoratorStart(_b);
  __decorateElement(_init5, 5, "timing", _timing_dec, State);
  __decorateElement(_init5, 5, "profiles", _profiles_dec, State);
  __decorateElement(_init5, 5, "clientCacheFlushInterval", _clientCacheFlushInterval_dec, State);
  __decoratorMetadata(_init5, State);
  NetworkServer2.State = State;
  function resolveTcpConfig(tcp) {
    if (tcp === true) {
      return { incoming: true, outgoing: true };
    }
    if (tcp === false || tcp === void 0) {
      return { incoming: false, outgoing: false };
    }
    return { incoming: tcp.incoming ?? false, outgoing: tcp.outgoing ?? false };
  }
  NetworkServer2.resolveTcpConfig = resolveTcpConfig;
})(NetworkServer || (NetworkServer = {}));
export {
  NetworkServer
};
//# sourceMappingURL=NetworkServer.js.map
