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 { Behavior } from "#behavior/Behavior.js";
import { Events as BaseEvents } from "#behavior/Events.js";
import { CommissioningClient } from "#behavior/system/commissioning/CommissioningClient.js";
import { NetworkClient } from "#behavior/system/network/NetworkClient.js";
import { BasicInformationClient } from "#behaviors/basic-information";
import { IcdManagementClient } from "#behaviors/icd-management";
import { OperationalCredentialsClient } from "#behaviors/operational-credentials";
import { Node } from "#node/Node.js";
import {
  Crypto,
  ImplementationError,
  Logger,
  Millis,
  Observable,
  Seconds,
  Time
} from "@matter/general";
import { bool, field, nonvolatile, octstr, subjectId, systimeMs, uint32, uint8 } from "@matter/model";
import { FabricManager, PeerAddress, PeerSet, SUBSCRIPTION_PROCESSING_TIME } from "@matter/protocol";
import { SubjectId } from "@matter/types";
import { IcdManagement } from "@matter/types/clusters/icd-management";
import { IcdMultiAdminError } from "./IcdMultiAdminError.js";
const logger = Logger.get("IcdClient");
class IcdClient extends Behavior {
  static early = true;
  static id = "icd";
  get isRegistered() {
    return this.state.registered;
  }
  /** Whether the peer is LIT-capable (LongIdleTimeSupport feature and specification version >= 1.4.0). */
  get peerSupportsLit() {
    return IcdClient.litSupported(this.endpoint);
  }
  /**
   * Whether the peer is currently awake. A non-LIT or not-yet-fed peer has nothing to await and reads true.
   */
  get awake() {
    return this.#fedWakefulness()?.awake.value ?? true;
  }
  /**
   * Deadline by which the next Check-In from a registered LIT peer is expected, or undefined when no Check-In is
   * scheduled (no fed peer / not registered / not LIT). Derived from the fed peer's wakefulness availability window.
   */
  get nextExpectedCheckin() {
    return this.#fedWakefulness()?.availableUntil;
  }
  get #peerIsLongIdleTimeOperating() {
    return this.peerSupportsLit && this.endpoint.maybeStateOf(IcdManagementClient)?.operatingMode === IcdManagement.OperatingMode.Lit;
  }
  initialize() {
    if (this.endpoint instanceof Node) {
      this.reactTo(this.endpoint.lifecycle.decommissioned, this.#onDecommissioned);
    }
    const owner = this.endpoint.owner;
    if (owner instanceof Node) {
      this.reactTo(owner.lifecycle.online, this.#restoreReceivePath);
      if (owner.lifecycle.isOnline) {
        this.#restoreReceivePath();
      }
    }
    if (this.endpoint.behaviors.has(IcdManagementClient)) {
      this.maybeReactTo(
        this.endpoint.eventsOf(IcdManagementClient).operatingMode$Changed,
        this.#onOperatingModeChanged
      );
    }
    if (this.endpoint instanceof Node) {
      this.reactTo(this.endpoint.lifecycle.online, this.#onPeerOnline);
      this.reactTo(
        this.endpoint.eventsOf(NetworkClient).subscriptionStatusChanged,
        this.#onSubscriptionStatusChanged
      );
      if (this.agent.get(NetworkClient).subscriptionActive) {
        this.#ensureLitRegistration();
      }
    }
  }
  /**
   * The peer coming online is live proof it is awake, so re-arm its wakefulness like a Check-In would; a no-op for a
   * non-LIT or unfed peer.
   */
  #onPeerOnline() {
    this.#fedWakefulness()?.noteSignal();
  }
  #onSubscriptionStatusChanged(isActive) {
    if (isActive) {
      this.#ensureLitRegistration();
    }
  }
  #onOperatingModeChanged() {
    const wakefulness = this.#fedWakefulness();
    if (wakefulness !== void 0) {
      const litOperating = this.#peerIsLongIdleTimeOperating;
      wakefulness.requiresAwait = litOperating;
      if (litOperating && this.endpoint instanceof Node && this.endpoint.lifecycle.isOnline) {
        wakefulness.noteSignal();
      }
    }
    this.#ensureLitRegistration();
  }
  /**
   * Register as a Check-In client for a LIT peer. Mandatory for LIT peers, so it bypasses the multi-admin check.
   * Best-effort: a failure is logged and retried by the next trigger.
   */
  #ensureLitRegistration() {
    if (!this.peerSupportsLit || !this.agent.get(NetworkClient).subscriptionActive || this.state.registered) {
      return;
    }
    if (this.internal.autoRegister !== void 0) {
      this.internal.autoRegisterPending = true;
      return;
    }
    this.internal.autoRegister = this.#autoRegister();
  }
  async #autoRegister() {
    try {
      await Promise.resolve();
      await this.endpoint.act("icd-auto-register", async (agent) => {
        const icd = agent.get(IcdClient);
        if (icd.state.registered || !(icd.endpoint instanceof Node) || !icd.endpoint.lifecycle.isOnline || !IcdClient.litSupported(icd.endpoint)) {
          return;
        }
        const { operatingMode } = await icd.endpoint.getStateOf(IcdManagementClient, ["operatingMode"]);
        if (operatingMode !== IcdManagement.OperatingMode.Lit && !await icd.#dslsPeerHasRegistrations()) {
          return;
        }
        await icd.register({ allowMultiAdmin: true });
      });
    } catch (error) {
      logger.warn(`ICD auto-registration for LIT peer ${this.#peerAddress} failed`, error);
    } finally {
      this.internal.autoRegister = void 0;
    }
    if (this.internal.autoRegisterPending) {
      this.internal.autoRegisterPending = void 0;
      this.internal.autoRegister = this.#autoRegister();
    }
  }
  /**
   * True when the peer supports DSLS and already has at least one registered Check-In client. Read non-fabric-scoped
   * because a co-admin's registration lives on its own fabric.
   */
  async #dslsPeerHasRegistrations() {
    if (this.endpoint.maybeFeaturesOf(IcdManagementClient)?.dynamicSitLitSupport !== true) {
      return false;
    }
    const { registeredClients } = await this.endpoint.getStateOf(IcdManagementClient, ["registeredClients"], {
      fabricFilter: false
    });
    return (registeredClients?.length ?? 0) > 0;
  }
  /** The {@link IcdPeerWakefulness} for the currently fed peer, or undefined when no peer is fed. */
  #fedWakefulness() {
    const fedPeer = this.internal.fedPeer;
    if (fedPeer === void 0) {
      return void 0;
    }
    return this.env.get(FabricManager).maybeFor(fedPeer.fabricIndex)?.icd.wakefulnessFor(fedPeer.nodeId);
  }
  /**
   * Re-arm the Check-In receive path from persisted registration state. The {@link FabricIcd} peer entry is
   * runtime-only, so it is rebuilt on every controller online.
   */
  #restoreReceivePath() {
    if (!this.state.registered || this.state.key === void 0) {
      return;
    }
    const { fabric, peerNodeId } = this.#fabricContext();
    this.#feedFabricIcd(fabric, peerNodeId, false);
  }
  /**
   * Decommission already removed our fabric from the peer, so no peer {@link IcdManagement.unregisterClient} is
   * possible or needed — only local cleanup.
   */
  #onDecommissioned() {
    if (this.state.registered) {
      this.#clearRegistration();
    }
  }
  #clearRegistration() {
    this.#dropFedPeer();
    this.state.registered = false;
    this.state.key = void 0;
    this.state.counterStart = void 0;
    this.state.lastOffset = void 0;
    this.state.monitoredSubject = void 0;
    this.state.clientType = void 0;
    this.state.lastCheckInReceivedAt = void 0;
    this.state.available = false;
    this.events.unregistered.emit();
  }
  #dropFedPeer() {
    const fedPeer = this.internal.fedPeer;
    if (fedPeer === void 0) {
      return;
    }
    this.#unsubscribeAvailable();
    this.#unsubscribeCheckInMissed();
    this.env.get(FabricManager).maybeFor(fedPeer.fabricIndex)?.icd.deletePeer(fedPeer.nodeId);
    this.internal.fedPeer = void 0;
  }
  #unsubscribeAvailable() {
    const { availableSource, availableListener } = this.internal;
    if (availableSource !== void 0 && availableListener !== void 0) {
      availableSource.off(availableListener);
    }
    this.internal.availableSource = void 0;
    this.internal.availableListener = void 0;
  }
  #unsubscribeCheckInMissed() {
    const { checkInMissedSource, checkInMissedListener } = this.internal;
    if (checkInMissedSource !== void 0 && checkInMissedListener !== void 0) {
      checkInMissedSource.off(checkInMissedListener);
    }
    this.internal.checkInMissedSource = void 0;
    this.internal.checkInMissedListener = void 0;
  }
  /**
   * Register this controller as a Check-In client on the peer.
   *
   * Installs a shared {@link IcdManagement.RegisterClientRequest.key} on the peer so it can send us encrypted
   * Check-In messages, records the rolling-counter baseline in {@link IcdClient.State}, and arms the controller-side Check-In
   * receive path on the fabric.
   *
   * @throws {ImplementationError} if the peer is not online (registration reads from and writes to the peer), or its
   *   IcdManagement cluster lacks the Check-In Protocol feature.
   * @throws {IcdMultiAdminError} if the peer has more than one administrator from other vendors and
   *   `allowMultiAdmin` is not set — see {@link IcdMultiAdminError.assertSingleAdmin}.
   */
  async register(options) {
    if (this.state.registered) {
      throw new ImplementationError(
        "ICD client is already registered; unregister first or let key refresh re-key in place."
      );
    }
    if (!this.agent.get(NetworkClient).subscriptionActive) {
      throw new ImplementationError(
        "ICD registration requires an active subscription so the peer operating mode is not stale."
      );
    }
    if (!(this.endpoint instanceof Node) || !this.endpoint.lifecycle.isOnline) {
      throw new ImplementationError("ICD registration requires the peer node to be online.");
    }
    if (!this.endpoint.maybeFeaturesOf(IcdManagementClient)?.checkInProtocolSupport) {
      throw new ImplementationError(
        "ICD registration refused: peer does not support the Check-In Protocol (CIP)."
      );
    }
    const { fabric, ownNodeId, peerNodeId } = this.#fabricContext();
    const {
      monitoredSubject = SubjectId(ownNodeId),
      clientType = IcdManagement.ClientType.Permanent,
      allowMultiAdmin = false,
      ignoredVendors = IcdMultiAdminError.TRUSTED_ECOSYSTEM_VENDORS
    } = options ?? {};
    const fabrics = await this.#readPeerFabrics();
    IcdMultiAdminError.assertSingleAdmin(
      fabrics.map((f) => f.vendorId),
      ignoredVendors,
      allowMultiAdmin
    );
    const key = this.env.get(Crypto).randomBytes(16);
    const { icdCounter } = await this.#peerIcd().registerClient({
      checkInNodeId: ownNodeId,
      monitoredSubject,
      key,
      clientType
    });
    this.state.key = key;
    this.state.counterStart = icdCounter;
    this.state.lastOffset = 0;
    this.state.monitoredSubject = monitoredSubject;
    this.state.clientType = clientType;
    this.state.registered = true;
    this.#feedFabricIcd(fabric, peerNodeId, true);
    this.events.registered.emit();
  }
  /**
   * Remove this controller's Check-In registration from the peer and tear down the local receive path.
   *
   * Best-effort on the peer: local state is cleared even if the peer {@link IcdManagement.unregisterClient} fails (it
   * may be unreachable). A no-op when not registered.
   */
  async unregister() {
    if (!this.state.registered) {
      return;
    }
    this.state.registered = false;
    await this.internal.keyRefresh;
    const { ownNodeId } = this.#fabricContext();
    try {
      await this.#peerIcd().unregisterClient({ checkInNodeId: ownNodeId, verificationKey: this.state.key });
    } finally {
      this.#clearRegistration();
    }
  }
  /**
   * Locally drop this controller's Check-In registration without contacting the peer.
   *
   * Escape hatch for an unreachable registered LIT peer: {@link unregister} round-trips to the peer, so it parks on
   * the same wakefulness deadlock this clears. Dropping the fed peer removes its wakefulness, so subsequent
   * interactions no longer hold — a later subscribe can re-establish and re-register. The peer keeps a stale
   * registration for us until it prunes it (or a fresh {@link register} mints a new key). A no-op when not registered.
   */
  async forget() {
    if (!this.state.registered) {
      return;
    }
    this.state.registered = false;
    await this.internal.keyRefresh;
    logger.info("ICD registration forgotten locally (no peer UnregisterClient); peer retains a stale registration");
    this.#clearRegistration();
  }
  /**
   * Ask the peer to remain in Active mode for at least `duration` and return the duration it actually promised.
   *
   * @see {@link MatterSpecification.v16.Core} § 9.16.7.4
   */
  async stayActive(duration) {
    const { promisedActiveDuration } = await this.#peerIcd().stayActiveRequest({
      stayActiveDuration: Millis.of(duration)
    });
    const promised = Millis(promisedActiveDuration);
    this.#fedWakefulness()?.noteStayActive(promised);
    return promised;
  }
  #fabricContext() {
    const peerAddress = this.endpoint.stateOf(CommissioningClient).peerAddress;
    if (peerAddress === void 0) {
      throw new ImplementationError("ICD registration requires a commissioned peer.");
    }
    const { fabricIndex, nodeId: peerNodeId } = peerAddress;
    const fabric = this.env.get(FabricManager).for(fabricIndex);
    const ownNodeId = fabric.nodeId;
    return { fabric, ownNodeId, peerNodeId };
  }
  async #readPeerFabrics() {
    const { fabrics } = await this.endpoint.getStateOf(OperationalCredentialsClient, ["fabrics"], {
      fabricFilter: false
    });
    return fabrics ?? [];
  }
  #peerIcd() {
    return this.agent.get(IcdManagementClient);
  }
  /**
   * Peer address for log context; undefined before commissioning. Reads the sync state view, so safe off-transaction.
   * Interned via {@link PeerAddress} so a rehydrated plain-struct address renders `@fabric:node` rather than
   * `[object Object]`.
   */
  get #peerAddress() {
    return PeerAddress(this.endpoint.maybeStateOf(CommissioningClient)?.peerAddress);
  }
  #feedFabricIcd(fabric, peerNodeId, seed) {
    const { key, counterStart, lastOffset } = this.state;
    if (key === void 0 || counterStart === void 0 || lastOffset === void 0) {
      throw new ImplementationError("ICD peer cannot be fed to the fabric before registration state is set.");
    }
    if (this.internal.checkInHandler === void 0) {
      this.internal.checkInHandler = this.callback(this.#onCheckIn, { offline: true, lock: true });
    }
    fabric.icd.addPeer({ peerNodeId, key, counterStart, lastOffset }, this.internal.checkInHandler);
    this.internal.fedPeer = PeerAddress({ fabricIndex: fabric.fabricIndex, nodeId: peerNodeId });
    const wakefulness = fabric.icd.wakefulnessFor(peerNodeId);
    if (wakefulness === void 0) {
      return;
    }
    const icdState = this.endpoint.maybeStateOf(IcdManagementClient);
    const peer = this.env.get(PeerSet).get(this.internal.fedPeer);
    wakefulness.setTimings({
      activeModeThreshold: icdState?.activeModeThreshold === void 0 ? void 0 : Millis(icdState.activeModeThreshold),
      idleModeDuration: icdState?.idleModeDuration === void 0 ? void 0 : Seconds(icdState.idleModeDuration),
      reportMargin: peer === void 0 ? void 0 : Millis(peer.exchangeProvider.maximumPeerResponseTime(SUBSCRIPTION_PROCESSING_TIME) * 2)
    });
    wakefulness.requiresAwait = this.#peerIsLongIdleTimeOperating;
    if (seed) {
      wakefulness.noteSignal();
    }
    this.#unsubscribeAvailable();
    const listener = this.callback(this.#onAvailableChanged, { offline: true, lock: true });
    wakefulness.available.on(listener);
    this.internal.availableSource = wakefulness.available;
    this.internal.availableListener = listener;
    this.state.available = wakefulness.available.value === true;
    this.#unsubscribeCheckInMissed();
    const checkInMissedListener = this.callback(this.#onCheckInMissed, { offline: true, lock: true });
    wakefulness.checkInMissed.on(checkInMissedListener);
    this.internal.checkInMissedSource = wakefulness.checkInMissed;
    this.internal.checkInMissedListener = checkInMissedListener;
  }
  #onAvailableChanged(available) {
    this.state.available = available;
  }
  #onCheckInMissed() {
    this.events.checkInMissed.emit();
  }
  #onCheckIn(checkIn) {
    const { offset, counter, activeModeThreshold, refreshNeeded } = checkIn;
    this.state.lastOffset = offset;
    this.state.lastCheckInReceivedAt = Time.nowMs;
    this.events.checkedIn.emit({ counter, activeModeThreshold });
    if (refreshNeeded && this.state.registered && this.internal.keyRefresh === void 0) {
      this.internal.keyRefresh = this.#startKeyRefresh();
    }
  }
  async #startKeyRefresh() {
    try {
      await Promise.resolve();
      await this.endpoint.act("icd-key-refresh", (agent) => agent.get(IcdClient).#refreshKey());
    } catch (error) {
      if (error instanceof ImplementationError) {
        logger.error(
          `ICD key refresh for peer ${this.#peerAddress} failed unexpectedly; controller and peer keys may be out of sync`,
          error
        );
      } else {
        logger.warn(`ICD key refresh for peer ${this.#peerAddress} failed; will retry on next check-in`, error);
      }
    } finally {
      this.internal.keyRefresh = void 0;
    }
  }
  /**
   * Re-key the registration in place before the rolling counter offset reaches 2³¹.
   *
   * @see {@link MatterSpecification.v16.Core} § 4.22.3.4.1
   */
  async #refreshKey() {
    const { fabric, ownNodeId, peerNodeId } = this.#fabricContext();
    const { monitoredSubject, clientType } = this.state;
    if (monitoredSubject === void 0 || clientType === void 0) {
      throw new ImplementationError("ICD key refresh requires an existing registration.");
    }
    const verificationKey = this.state.key;
    const key = this.env.get(Crypto).randomBytes(16);
    const { icdCounter } = await this.#peerIcd().registerClient({
      checkInNodeId: ownNodeId,
      monitoredSubject,
      key,
      clientType,
      verificationKey
    });
    this.state.key = key;
    this.state.counterStart = icdCounter;
    this.state.lastOffset = 0;
    fabric.icd.updatePeer(peerNodeId, { key, counterStart: icdCounter, lastOffset: 0 });
    this.events.keyRefreshed.emit();
  }
  /**
   * Wait for an in-flight key refresh to finish on teardown — aborting between the peer re-key and our state write
   * would leave the controller and peer with mismatched keys.
   */
  async [Symbol.asyncDispose]() {
    await this.internal.autoRegister;
    await this.internal.keyRefresh;
    await super[Symbol.asyncDispose]?.();
  }
}
((IcdClient2) => {
  var _available_dec, _lastCheckInReceivedAt_dec, _registered_dec, _clientType_dec, _monitoredSubject_dec, _lastOffset_dec, _counterStart_dec, _key_dec, _init;
  IcdClient2.MIN_LIT_SPECIFICATION_VERSION = 17039360;
  function litSupported(endpoint) {
    if (endpoint.maybeFeaturesOf(IcdManagementClient)?.longIdleTimeSupport !== true) {
      return false;
    }
    return (endpoint.maybeStateOf(BasicInformationClient)?.specificationVersion ?? 0) >= IcdClient2.MIN_LIT_SPECIFICATION_VERSION;
  }
  IcdClient2.litSupported = litSupported;
  class Internal {
    /** Retained across re-registrations so the protocol RX path stays armed without creating a second closure. */
    checkInHandler;
    /** In-flight key refresh; tracked so a second refreshNeeded Check-In can't overlap it and teardown can await it. */
    keyRefresh;
    /** In-flight LIT auto-registration; tracked so overlapping triggers can't double-register and teardown can await it. */
    autoRegister;
    /** Set when a trigger arrives while {@link autoRegister} is in flight, so it re-evaluates on completion. */
    autoRegisterPending;
    /** Address of the peer fed to {@link FabricIcd}; lets decommission drop it after peerAddress is already gone. */
    fedPeer;
    /** The fed peer's wakefulness `available` observable we currently mirror; recreated on every feed. */
    availableSource;
    /** Listener mirroring {@link availableSource} into {@link IcdClient.State.available}; removed on drop and before re-feed. */
    availableListener;
    /** The fed peer's wakefulness `checkInMissed` observable we currently mirror; recreated on every feed. */
    checkInMissedSource;
    /** Listener mirroring {@link checkInMissedSource} into {@link IcdClient.Events.checkInMissed}; removed on drop and before re-feed. */
    checkInMissedListener;
  }
  IcdClient2.Internal = Internal;
  _key_dec = [field(octstr, nonvolatile)], _counterStart_dec = [field(uint32, nonvolatile)], _lastOffset_dec = [field(uint32, nonvolatile)], _monitoredSubject_dec = [field(subjectId, nonvolatile)], _clientType_dec = [field(uint8, nonvolatile)], _registered_dec = [field(bool, nonvolatile)], _lastCheckInReceivedAt_dec = [field(systimeMs)], _available_dec = [field(bool)];
  class State {
    constructor() {
      __publicField(this, "key", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
      __publicField(this, "counterStart", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
      __publicField(this, "lastOffset", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
      __publicField(this, "monitoredSubject", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
      __publicField(this, "clientType", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
      __publicField(this, "registered", __runInitializers(_init, 28, this, false)), __runInitializers(_init, 31, this);
      __publicField(this, "lastCheckInReceivedAt", __runInitializers(_init, 32, this)), __runInitializers(_init, 35, this);
      __publicField(this, "available", __runInitializers(_init, 36, this, false)), __runInitializers(_init, 39, this);
    }
  }
  _init = __decoratorStart(null);
  __decorateElement(_init, 5, "key", _key_dec, State);
  __decorateElement(_init, 5, "counterStart", _counterStart_dec, State);
  __decorateElement(_init, 5, "lastOffset", _lastOffset_dec, State);
  __decorateElement(_init, 5, "monitoredSubject", _monitoredSubject_dec, State);
  __decorateElement(_init, 5, "clientType", _clientType_dec, State);
  __decorateElement(_init, 5, "registered", _registered_dec, State);
  __decorateElement(_init, 5, "lastCheckInReceivedAt", _lastCheckInReceivedAt_dec, State);
  __decorateElement(_init, 5, "available", _available_dec, State);
  __decoratorMetadata(_init, State);
  IcdClient2.State = State;
  class Events extends BaseEvents {
    registered = Observable();
    unregistered = Observable();
    checkedIn = Observable();
    keyRefreshed = Observable();
    available$Changed = new Observable();
    /** Emits when a registered LIT peer misses its expected Check-In (its availability window lapsed). */
    checkInMissed = Observable();
  }
  IcdClient2.Events = Events;
})(IcdClient || (IcdClient = {}));
export {
  IcdClient
};
//# sourceMappingURL=IcdClient.js.map
