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 { SoftwareUpdateManager } from "#behavior/system/software-update/SoftwareUpdateManager.js";
import { OperationalCredentialsClient } from "#behaviors/operational-credentials";
import { OtaSoftwareUpdateProviderServer } from "#behaviors/ota-software-update-provider";
import { IdentityService } from "#node/server/IdentityService.js";
import {
  Diagnostic,
  ImplementationError,
  Logger,
  MatterError,
  NotImplementedError,
  Observable,
  ServerAddress,
  Time
} from "@matter/general";
import {
  bool,
  datatype,
  duration,
  fabricIdx,
  field,
  listOf,
  mandatory,
  map16,
  nodeId,
  nonvolatile,
  string,
  systimeMs,
  uint16,
  uint32,
  uint8,
  vendorId
} from "@matter/model";
import {
  ControllerCommissioner,
  FabricAuthority,
  FabricManager,
  Peer,
  PeerAddress,
  PeerSet,
  PeerAddress as ProtocolPeerAddress
} from "@matter/protocol";
import {
  ManualPairingCodeCodec
} from "@matter/types";
import { OperationalCredentials } from "@matter/types/clusters/operational-credentials";
import { ControllerBehavior } from "../controller/ControllerBehavior.js";
import { NetworkClient } from "../network/NetworkClient.js";
import { RemoteDescriptor } from "./RemoteDescriptor.js";
const logger = Logger.get("CommissioningClient");
class CommissioningClient extends Behavior {
  static early = true;
  static id = "commissioning";
  initialize(options) {
    const descriptor = options?.descriptor;
    if (descriptor) {
      this.descriptor = descriptor;
    }
    if (this.state.discoveredAt === void 0) {
      this.state.discoveredAt = Time.nowMs;
    }
    if (this.state.peerAddress !== void 0) {
      this.#bindPeer(this.state.peerAddress);
    }
    const node = this.endpoint;
    this.reactTo(node.lifecycle.partsReady, this.#initializeNode);
    this.reactTo(this.events.peerAddress$Changed, this.#peerAddressChanged);
    this.reactTo(this.events.addresses$Changed, this.#operationalAddressesChanged);
    this.reactTo(this.events.caseAuthenticatedTags$Changed, this.#catsChanged);
  }
  [Symbol.asyncDispose]() {
    const peer = this.endpoint.env.maybeGet(Peer);
    if (peer) {
      this.#unbindPeer(peer.address);
    }
  }
  #findServerOtaProviderEndpoint() {
    const node = this.endpoint.owner;
    for (const endpoint of node.endpoints) {
      if (endpoint.behaviors.has(OtaSoftwareUpdateProviderServer)) {
        return endpoint;
      }
    }
  }
  async commission(options) {
    const node = this.endpoint;
    if (this.state.peerAddress !== void 0) {
      throw new ImplementationError(`${node} is already commissioned`);
    }
    if (typeof options === "number") {
      options = { passcode: options };
    } else if (typeof options === "string") {
      options = { pairingCode: options };
    }
    const opts = CommissioningClient.PasscodeOptions(options);
    let { passcode } = opts;
    if (!Number.isFinite(passcode)) {
      passcode = Number.parseInt(passcode);
      if (!Number.isFinite(passcode)) {
        throw new ImplementationError(`You must provide the numeric passcode to commission a node`);
      }
    }
    await node.owner.act((agent) => agent.load(ControllerBehavior));
    const controller = node.owner.agentFor(this.context).get(ControllerBehavior);
    const fabricAuthority = opts.fabricAuthority ?? this.env.get(FabricAuthority);
    let { fabric } = opts;
    if (fabric === void 0) {
      if (this.context.fabric === void 0) {
        const config = await node.owner?.act((agent) => agent.get(ControllerBehavior).fabricAuthorityConfig);
        if (config === void 0) {
          throw new ImplementationError(
            `Cannot commission ${node} because no fabric was specified and the controller has no fabric configuration`
          );
        }
        fabric = await fabricAuthority.defaultFabric(config);
      } else {
        fabric = node.env.get(FabricManager).for(this.context.fabric);
      }
    }
    if (!fabricAuthority.hasControlOf(fabric)) {
      throw new ImplementationError(
        `Cannot commission ${node} fabric ${fabric.fabricIndex} because we do not control this fabric`
      );
    }
    const addresses = this.state.addresses;
    if (!addresses?.length) {
      throw new ImplementationError(`Cannot commission ${node} because the node has not been located`);
    }
    const commissioner = node.env.get(ControllerCommissioner);
    const address = await controller.allocatePeerAddress(fabric.fabricIndex, opts.nodeId);
    const commissioningOptions = {
      addresses: addresses.map(ServerAddress),
      fabric,
      nodeId: address.nodeId,
      passcode,
      discoveryData: this.descriptor,
      commissioningFlowImpl: options.commissioningFlowImpl
      // TODO Allow to configure all relevant commissioning options like
      //  * wifi/thread credentials
      //  * regulatory config
      //  * custom otaUpdateProviderLocation
    };
    const otaProviderEndpoint = this.#findServerOtaProviderEndpoint();
    if (otaProviderEndpoint !== void 0 && otaProviderEndpoint.stateOf(SoftwareUpdateManager).announceAsDefaultProvider) {
      commissioningOptions.otaUpdateProviderLocation = {
        nodeId: fabric.rootNodeId,
        endpoint: otaProviderEndpoint.number
      };
    }
    if (this.finalizeCommissioning !== CommissioningClient.prototype.finalizeCommissioning) {
      commissioningOptions.finalizeCommissioning = this.finalizeCommissioning.bind(this);
    }
    try {
      await commissioner.commission(commissioningOptions);
      this.state.peerAddress = address;
      this.state.commissionedAt = Time.nowMs;
      await this.#update(this.env.get(PeerSet).for(address));
    } catch (e) {
      this.env.get(IdentityService).releasePeerAddress(address);
      throw e;
    }
    if (opts.caseAuthenticatedTags !== void 0) {
      this.state.caseAuthenticatedTags = opts.caseAuthenticatedTags;
    }
    const network = this.agent.get(NetworkClient);
    network.state.defaultSubscription = opts.defaultSubscription;
    network.state.autoSubscribe = opts.autoSubscribe !== false;
    network.internal.isNewlyCommissioned = true;
    await this.context.transaction.commit();
    logger.notice(
      "Commissioned",
      Diagnostic.strong(this.endpoint.id),
      "as",
      Diagnostic.strong(this.endpoint.identity)
    );
    node.lifecycle.commissioned.emit(this.context);
    await node.start();
    return node;
  }
  /**
   * Remove this node from the fabric.
   *
   * After removal the {@link ClientNode} remains intact.  You can use {@link ClientNode#delete} to remove the node
   * permanently.
   *
   * Only legal if this node controls the peer's fabric.
   */
  async decommission() {
    const { peerAddress } = this.state;
    if (peerAddress === void 0) {
      throw new ImplementationError("Cannot decommission node that is not commissioned");
    }
    const formerAddress = ProtocolPeerAddress(peerAddress).toString();
    const opcreds = this.agent.get(OperationalCredentialsClient);
    const fabricIndex = opcreds.state.currentFabricIndex;
    logger.debug(`Removing node ${formerAddress} by removing fabric ${fabricIndex} on the node`);
    const result = await opcreds.removeFabric({ fabricIndex });
    if (result.statusCode !== OperationalCredentials.NodeOperationalCertStatus.Ok) {
      throw new MatterError(
        `Removing node ${formerAddress} failed with status ${result.statusCode} "${result.debugText}".`
      );
    }
    this.state.peerAddress = void 0;
    this.state.commissionedAt = void 0;
    await this.context.transaction.commit();
    logger.info(
      "Decommissioned",
      Diagnostic.strong(this.endpoint.id),
      "formerly",
      Diagnostic.strong(formerAddress)
    );
  }
  /**
   * Override to implement CASE commissioning yourself.
   *
   * If you override, matter.js commissions to the point where commissioning over PASE is complete.  You must then
   * complete commissioning yourself by connecting to the device and invoking the "CommissioningComplete" command.
   */
  async finalizeCommissioning(_address, _discoveryData) {
    throw new NotImplementedError();
  }
  get descriptor() {
    return RemoteDescriptor.fromLongForm(this.state);
  }
  set descriptor(descriptor) {
    RemoteDescriptor.toLongForm(descriptor, this.state);
  }
  #initializeNode() {
    const endpoint = this.endpoint;
    endpoint.lifecycle.initialized.emit(this.state.peerAddress !== void 0);
  }
  #operationalAddressesChanged(newAddresses, oldAddresses) {
    if (newAddresses === void 0) {
      logger.info("Operational address for", Diagnostic.strong(PeerAddress(this.state.peerAddress)), "cleared");
      return;
    }
    const newAddressesStr = newAddresses?.map((a) => ServerAddress.urlFor(a)).join(", ");
    if (oldAddresses === void 0) {
      logger.info(
        "Operational address for",
        Diagnostic.strong(PeerAddress(this.state.peerAddress)),
        "set to",
        Diagnostic.weak(newAddressesStr)
      );
      return;
    }
    const oldAddressesStr = oldAddresses.map((a) => ServerAddress.urlFor(a)).join(", ");
    if (oldAddressesStr !== newAddressesStr) {
      logger.info(
        "Operational address changed for",
        Diagnostic.strong(PeerAddress(this.state.peerAddress)),
        "from",
        Diagnostic.weak(oldAddressesStr),
        "to",
        Diagnostic.weak(newAddressesStr)
      );
    }
  }
  #peerAddressChanged(addr, oldAddr) {
    const node = this.endpoint;
    if (addr) {
      this.#bindPeer(addr);
      node.lifecycle.commissioned.emit(this.context);
    } else if (oldAddr) {
      this.#unbindPeer(oldAddr, true);
      node.lifecycle.decommissioned.emit(this.context);
    }
  }
  #catsChanged(cats) {
    if (!this.state.peerAddress) {
      return;
    }
    const node = this.endpoint;
    if (!node.env.has(PeerSet)) {
      return;
    }
    const peer = node.env.get(PeerSet).for(this.state.peerAddress);
    if (!peer) {
      return;
    }
    peer.descriptor.caseAuthenticatedTags = cats;
  }
  /**
   * Couple my {@link ClientNode} with the equivalent {@link Peer}.
   */
  #bindPeer(addr) {
    const node = this.endpoint;
    let peer = node.env.maybeGet(Peer);
    if (peer) {
      if (peer.address === addr && node.env.get(PeerSet).has(peer)) {
        return;
      }
      this.#unbindPeer(peer.address);
    }
    const peers = node.env.get(PeerSet);
    peer = peers.addKnownPeer({
      address: addr,
      operationalAddress: this.state.addresses?.filter((a) => a.type === "udp")?.[0],
      discoveryData: RemoteDescriptor.fromLongForm(this.state),
      caseAuthenticatedTags: this.state.caseAuthenticatedTags
    });
    peer.interaction = node.interaction;
    peer.protocol = node.protocol;
    this.internal.peerObserver = peer.updated.use(this.callback(this.#update));
    this.env.set(Peer, peer);
  }
  /**
   * Apply changes from the {@link Peer}.
   *
   * This persists information discovered via MDNS and the connection process.
   */
  async #update(peer) {
    const { transaction } = this.context;
    await transaction.addResources(this);
    await transaction.begin();
    if (peer.sessionParameters) {
      this.state.sessionParameters = peer.sessionParameters;
    }
    const {
      descriptor: { discoveryData, operationalAddress, caseAuthenticatedTags }
    } = peer;
    RemoteDescriptor.toLongForm(discoveryData, this.state);
    if (operationalAddress) {
      this.state.addresses = [operationalAddress];
    }
    this.state.caseAuthenticatedTags = caseAuthenticatedTags;
  }
  /**
   * Uncouple my {@link ClientNode} from a {@link Peer}.
   */
  #unbindPeer(addr, remove = false) {
    const node = this.endpoint;
    const peer = node.env.maybeGet(Peer);
    if (!peer || peer.address !== addr) {
      return;
    }
    node.env.delete(Peer, peer);
    this.internal.peerObserver?.[Symbol.dispose]();
    this.internal.peerObserver = void 0;
    if (peer.interaction === node.interaction) {
      peer.interaction = void 0;
    }
    if (peer.protocol === node.protocol) {
      peer.protocol = void 0;
    }
    if (remove) {
      node.env.get(PeerSet).peers.delete(peer);
    }
  }
}
((CommissioningClient2) => {
  var _nodeId_dec, _fabricIndex_dec, _init, _tcpServer_dec, _tcpClient_dec, _SupportedTransports_decorators, _init2, _maxTcpMessageSize_dec, _supportedTransports_dec, _maxPathsPerInvoke_dec, _specificationVersion_dec, _interactionModelRevision_dec, _dataModelRevision_dec, _activeThreshold_dec, _activeInterval_dec, _idleInterval_dec, _init3, _discoveredAt_dec, _ttl_dec, _peripheralAddress_dec, _port_dec, _ip_dec, _type_dec, _init4, _longIdleTimeOperatingMode_dec, _tcpSupport_dec, _sessionParameters_dec, _pairingInstructions_dec, _pairingHint_dec, _rotatingIdentifier_dec, _deviceName_dec, _deviceType_dec, _productId_dec, _vendorId_dec, _commissioningMode_dec, _discriminator_dec, _deviceIdentifier_dec, _ttl_dec2, _commissionedAt_dec, _offlineAt_dec, _onlineAt_dec, _discoveredAt_dec2, _addresses_dec, _caseAuthenticatedTags_dec, _peerAddress_dec, _init5;
  _fabricIndex_dec = [field(fabricIdx, mandatory)], _nodeId_dec = [field(nodeId, mandatory)];
  class PeerAddress2 {
    constructor(fabricIndex, nodeId2) {
      __publicField(this, "fabricIndex", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
      __publicField(this, "nodeId", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
      this.fabricIndex = fabricIndex;
      this.nodeId = nodeId2;
    }
  }
  _init = __decoratorStart(null);
  __decorateElement(_init, 5, "fabricIndex", _fabricIndex_dec, PeerAddress2);
  __decorateElement(_init, 5, "nodeId", _nodeId_dec, PeerAddress2);
  __decoratorMetadata(_init, PeerAddress2);
  CommissioningClient2.PeerAddress = PeerAddress2;
  _SupportedTransports_decorators = [datatype(map16)], _tcpClient_dec = [field(uint16.extend({ constraint: "1" }))], _tcpServer_dec = [field(uint16.extend({ constraint: "2" }))];
  class SupportedTransports {
    constructor() {
      __publicField(this, "tcpClient", __runInitializers(_init2, 8, this)), __runInitializers(_init2, 11, this);
      __publicField(this, "tcpServer", __runInitializers(_init2, 12, this)), __runInitializers(_init2, 15, this);
    }
  }
  _init2 = __decoratorStart(null);
  __decorateElement(_init2, 5, "tcpClient", _tcpClient_dec, SupportedTransports);
  __decorateElement(_init2, 5, "tcpServer", _tcpServer_dec, SupportedTransports);
  SupportedTransports = __decorateElement(_init2, 0, "SupportedTransports", _SupportedTransports_decorators, SupportedTransports);
  __runInitializers(_init2, 1, SupportedTransports);
  CommissioningClient2.SupportedTransports = SupportedTransports;
  _idleInterval_dec = [field(1, duration.extend({ constraint: "max 3600000" }))], _activeInterval_dec = [field(2, duration.extend({ constraint: "max 3600000" }))], _activeThreshold_dec = [field(3, duration.extend({ constraint: "max 65535" }))], _dataModelRevision_dec = [field(4, uint32)], _interactionModelRevision_dec = [field(5, uint16)], _specificationVersion_dec = [field(6, uint32)], _maxPathsPerInvoke_dec = [field(7, uint16)], _supportedTransports_dec = [field(8, SupportedTransports)], _maxTcpMessageSize_dec = [field(9, uint32)];
  class SessionParameters {
    constructor() {
      __publicField(this, "idleInterval", __runInitializers(_init3, 8, this)), __runInitializers(_init3, 11, this);
      __publicField(this, "activeInterval", __runInitializers(_init3, 12, this)), __runInitializers(_init3, 15, this);
      __publicField(this, "activeThreshold", __runInitializers(_init3, 16, this)), __runInitializers(_init3, 19, this);
      __publicField(this, "dataModelRevision", __runInitializers(_init3, 20, this)), __runInitializers(_init3, 23, this);
      __publicField(this, "interactionModelRevision", __runInitializers(_init3, 24, this)), __runInitializers(_init3, 27, this);
      __publicField(this, "specificationVersion", __runInitializers(_init3, 28, this)), __runInitializers(_init3, 31, this);
      __publicField(this, "maxPathsPerInvoke", __runInitializers(_init3, 32, this)), __runInitializers(_init3, 35, this);
      __publicField(this, "supportedTransports", __runInitializers(_init3, 36, this)), __runInitializers(_init3, 39, this);
      __publicField(this, "maxTcpMessageSize", __runInitializers(_init3, 40, this)), __runInitializers(_init3, 43, this);
    }
  }
  _init3 = __decoratorStart(null);
  __decorateElement(_init3, 5, "idleInterval", _idleInterval_dec, SessionParameters);
  __decorateElement(_init3, 5, "activeInterval", _activeInterval_dec, SessionParameters);
  __decorateElement(_init3, 5, "activeThreshold", _activeThreshold_dec, SessionParameters);
  __decorateElement(_init3, 5, "dataModelRevision", _dataModelRevision_dec, SessionParameters);
  __decorateElement(_init3, 5, "interactionModelRevision", _interactionModelRevision_dec, SessionParameters);
  __decorateElement(_init3, 5, "specificationVersion", _specificationVersion_dec, SessionParameters);
  __decorateElement(_init3, 5, "maxPathsPerInvoke", _maxPathsPerInvoke_dec, SessionParameters);
  __decorateElement(_init3, 5, "supportedTransports", _supportedTransports_dec, SessionParameters);
  __decorateElement(_init3, 5, "maxTcpMessageSize", _maxTcpMessageSize_dec, SessionParameters);
  __decoratorMetadata(_init3, SessionParameters);
  CommissioningClient2.SessionParameters = SessionParameters;
  _type_dec = [field(string, mandatory)], _ip_dec = [field(string)], _port_dec = [field(uint16)], _peripheralAddress_dec = [field(string)], _ttl_dec = [field(uint32)], _discoveredAt_dec = [field(systimeMs)];
  class NetworkAddress {
    constructor(address) {
      __publicField(this, "type", __runInitializers(_init4, 8, this)), __runInitializers(_init4, 11, this);
      __publicField(this, "ip", __runInitializers(_init4, 12, this)), __runInitializers(_init4, 15, this);
      __publicField(this, "port", __runInitializers(_init4, 16, this)), __runInitializers(_init4, 19, this);
      __publicField(this, "peripheralAddress", __runInitializers(_init4, 20, this)), __runInitializers(_init4, 23, this);
      __publicField(this, "ttl", __runInitializers(_init4, 24, this)), __runInitializers(_init4, 27, this);
      __publicField(this, "discoveredAt", __runInitializers(_init4, 28, this)), __runInitializers(_init4, 31, this);
      this.type = address.type;
      this.ip = address.ip;
      this.port = address.port;
      this.peripheralAddress = address.peripheralAddress;
      this.ttl = address.ttl;
      this.discoveredAt = address.discoveredAt;
    }
  }
  _init4 = __decoratorStart(null);
  __decorateElement(_init4, 5, "type", _type_dec, NetworkAddress);
  __decorateElement(_init4, 5, "ip", _ip_dec, NetworkAddress);
  __decorateElement(_init4, 5, "port", _port_dec, NetworkAddress);
  __decorateElement(_init4, 5, "peripheralAddress", _peripheralAddress_dec, NetworkAddress);
  __decorateElement(_init4, 5, "ttl", _ttl_dec, NetworkAddress);
  __decorateElement(_init4, 5, "discoveredAt", _discoveredAt_dec, NetworkAddress);
  __decoratorMetadata(_init4, NetworkAddress);
  CommissioningClient2.NetworkAddress = NetworkAddress;
  class Internal {
    peerObserver;
  }
  CommissioningClient2.Internal = Internal;
  _peerAddress_dec = [field(PeerAddress2, nonvolatile)], _caseAuthenticatedTags_dec = [field(listOf(uint32), nonvolatile)], _addresses_dec = [field(listOf(NetworkAddress), nonvolatile)], _discoveredAt_dec2 = [field(systimeMs, nonvolatile)], _onlineAt_dec = [field(systimeMs)], _offlineAt_dec = [field(systimeMs)], _commissionedAt_dec = [field(systimeMs, nonvolatile)], _ttl_dec2 = [field(duration, nonvolatile)], _deviceIdentifier_dec = [field(string, nonvolatile)], _discriminator_dec = [field(uint16, nonvolatile)], _commissioningMode_dec = [field(uint8, nonvolatile)], _vendorId_dec = [field(vendorId, nonvolatile)], _productId_dec = [field(uint16, nonvolatile)], _deviceType_dec = [field(uint16, nonvolatile)], _deviceName_dec = [field(string, nonvolatile)], _rotatingIdentifier_dec = [field(string, nonvolatile)], _pairingHint_dec = [field(uint32, nonvolatile)], _pairingInstructions_dec = [field(string, nonvolatile)], _sessionParameters_dec = [field(SessionParameters, nonvolatile)], _tcpSupport_dec = [field(uint8, nonvolatile)], _longIdleTimeOperatingMode_dec = [field(bool, nonvolatile)];
  class State {
    constructor() {
      __publicField(this, "peerAddress", __runInitializers(_init5, 8, this)), __runInitializers(_init5, 11, this);
      __publicField(this, "caseAuthenticatedTags", __runInitializers(_init5, 12, this)), __runInitializers(_init5, 15, this);
      __publicField(this, "addresses", __runInitializers(_init5, 16, this)), __runInitializers(_init5, 19, this);
      __publicField(this, "discoveredAt", __runInitializers(_init5, 20, this)), __runInitializers(_init5, 23, this);
      __publicField(this, "onlineAt", __runInitializers(_init5, 24, this)), __runInitializers(_init5, 27, this);
      __publicField(this, "offlineAt", __runInitializers(_init5, 28, this)), __runInitializers(_init5, 31, this);
      __publicField(this, "commissionedAt", __runInitializers(_init5, 32, this)), __runInitializers(_init5, 35, this);
      __publicField(this, "ttl", __runInitializers(_init5, 36, this)), __runInitializers(_init5, 39, this);
      __publicField(this, "deviceIdentifier", __runInitializers(_init5, 40, this)), __runInitializers(_init5, 43, this);
      __publicField(this, "discriminator", __runInitializers(_init5, 44, this)), __runInitializers(_init5, 47, this);
      __publicField(this, "commissioningMode", __runInitializers(_init5, 48, this)), __runInitializers(_init5, 51, this);
      __publicField(this, "vendorId", __runInitializers(_init5, 52, this)), __runInitializers(_init5, 55, this);
      __publicField(this, "productId", __runInitializers(_init5, 56, this)), __runInitializers(_init5, 59, this);
      __publicField(this, "deviceType", __runInitializers(_init5, 60, this)), __runInitializers(_init5, 63, this);
      __publicField(this, "deviceName", __runInitializers(_init5, 64, this)), __runInitializers(_init5, 67, this);
      __publicField(this, "rotatingIdentifier", __runInitializers(_init5, 68, this)), __runInitializers(_init5, 71, this);
      __publicField(this, "pairingHint", __runInitializers(_init5, 72, this)), __runInitializers(_init5, 75, this);
      __publicField(this, "pairingInstructions", __runInitializers(_init5, 76, this)), __runInitializers(_init5, 79, this);
      __publicField(this, "sessionParameters", __runInitializers(_init5, 80, this)), __runInitializers(_init5, 83, this);
      __publicField(this, "tcpSupport", __runInitializers(_init5, 84, this)), __runInitializers(_init5, 87, this);
      __publicField(this, "longIdleTimeOperatingMode", __runInitializers(_init5, 88, this)), __runInitializers(_init5, 91, this);
    }
  }
  _init5 = __decoratorStart(null);
  __decorateElement(_init5, 5, "peerAddress", _peerAddress_dec, State);
  __decorateElement(_init5, 5, "caseAuthenticatedTags", _caseAuthenticatedTags_dec, State);
  __decorateElement(_init5, 5, "addresses", _addresses_dec, State);
  __decorateElement(_init5, 5, "discoveredAt", _discoveredAt_dec2, State);
  __decorateElement(_init5, 5, "onlineAt", _onlineAt_dec, State);
  __decorateElement(_init5, 5, "offlineAt", _offlineAt_dec, State);
  __decorateElement(_init5, 5, "commissionedAt", _commissionedAt_dec, State);
  __decorateElement(_init5, 5, "ttl", _ttl_dec2, State);
  __decorateElement(_init5, 5, "deviceIdentifier", _deviceIdentifier_dec, State);
  __decorateElement(_init5, 5, "discriminator", _discriminator_dec, State);
  __decorateElement(_init5, 5, "commissioningMode", _commissioningMode_dec, State);
  __decorateElement(_init5, 5, "vendorId", _vendorId_dec, State);
  __decorateElement(_init5, 5, "productId", _productId_dec, State);
  __decorateElement(_init5, 5, "deviceType", _deviceType_dec, State);
  __decorateElement(_init5, 5, "deviceName", _deviceName_dec, State);
  __decorateElement(_init5, 5, "rotatingIdentifier", _rotatingIdentifier_dec, State);
  __decorateElement(_init5, 5, "pairingHint", _pairingHint_dec, State);
  __decorateElement(_init5, 5, "pairingInstructions", _pairingInstructions_dec, State);
  __decorateElement(_init5, 5, "sessionParameters", _sessionParameters_dec, State);
  __decorateElement(_init5, 5, "tcpSupport", _tcpSupport_dec, State);
  __decorateElement(_init5, 5, "longIdleTimeOperatingMode", _longIdleTimeOperatingMode_dec, State);
  __decoratorMetadata(_init5, State);
  CommissioningClient2.State = State;
  class Events extends BaseEvents {
    peerAddress$Changed = new Observable();
    addresses$Changed = new Observable();
    caseAuthenticatedTags$Changed = new Observable();
  }
  CommissioningClient2.Events = Events;
  function PasscodeOptions(options) {
    let opts;
    if ("pairingCode" in options) {
      const decoded = ManualPairingCodeCodec.decode(options.pairingCode);
      opts = {
        ...options,
        ...decoded
      };
    } else {
      opts = options;
    }
    let { passcode } = opts;
    if (typeof passcode !== "number" || !Number.isFinite(passcode)) {
      passcode = Number.parseInt(passcode);
      if (!Number.isFinite(passcode)) {
        throw new ImplementationError("You must provide a pairing code or passcode to pair a node");
      }
    }
    return opts;
  }
  CommissioningClient2.PasscodeOptions = PasscodeOptions;
})(CommissioningClient || (CommissioningClient = {}));
export {
  CommissioningClient
};
//# sourceMappingURL=CommissioningClient.js.map
