/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { CommissioningClient } from "#behavior/system/commissioning/CommissioningClient.js";
import { ChannelType, Minutes } from "@matter/general";
import { ParallelPaseDiscovery } from "./ParallelPaseDiscovery.js";
class CommissioningDiscovery extends ParallelPaseDiscovery {
  #options;
  constructor(owner, options) {
    const opts = CommissioningClient.PasscodeOptions(options);
    const { discriminator } = opts;
    if (discriminator !== void 0) {
      options = { ...options, longDiscriminator: discriminator };
    }
    if (options.timeout === void 0) {
      options = { ...options, timeout: Minutes(3) };
    }
    if (options.discoveryCapabilities !== void 0 && options.scannerFilter === void 0) {
      const caps = options.discoveryCapabilities;
      options = {
        ...options,
        scannerFilter: (s) => s.type === ChannelType.UDP || !!caps.ble && s.type === ChannelType.BLE
      };
    }
    super(owner, options);
    this.#options = options;
  }
  get cleanupLabel() {
    return "Commissioning candidate cleanup";
  }
  get failureMessage() {
    return "No device could be commissioned";
  }
  onDiscovered(node) {
    if (this.paseWon) return;
    const peers = this.owner.peers;
    this.registerAttempt(
      (winOnPase) => peers.runCommissioning(
        node,
        () => node.act(
          "commission",
          (agent) => agent.commissioning.commission({
            ...this.#options,
            abort: this.abortSignal,
            continueCommissioningAfterPase: winOnPase
          })
        )
      ),
      () => node
    );
  }
}
export {
  CommissioningDiscovery
};
//# sourceMappingURL=CommissioningDiscovery.js.map
