/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Seconds, ServerAddress } from "@matter/general";
import { ControllerCommissioner } from "@matter/protocol";
import { ParallelPaseDiscovery } from "./ParallelPaseDiscovery.js";
class PaseDiscovery extends ParallelPaseDiscovery {
  #options;
  constructor(owner, options) {
    if (options.timeout === void 0) {
      options = { ...options, timeout: Seconds(60) };
    }
    super(owner, options);
    this.#options = options;
  }
  get cleanupLabel() {
    return "PASE candidate cleanup";
  }
  get failureMessage() {
    return "No PASE session could be established";
  }
  onDiscovered(node) {
    if (this.paseWon) return;
    this.registerAttempt(
      (winOnPase) => node.act("establish-pase", (agent) => {
        const addresses = agent.commissioning.state.addresses;
        if (!addresses?.length) {
          return;
        }
        const commissioner = node.env.get(ControllerCommissioner);
        const establishOptions = {
          addresses: addresses.map(ServerAddress),
          discoveryData: agent.commissioning.descriptor,
          passcode: this.#options.passcode,
          timeout: this.#options.timeout,
          abort: this.abortSignal,
          continueAfterPase: winOnPase
        };
        return commissioner.establishPase(establishOptions);
      }),
      (result) => result?.paseSession
    );
  }
}
export {
  PaseDiscovery
};
//# sourceMappingURL=PaseDiscovery.js.map
