/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { IndexBehavior } from "#behavior/system/index/IndexBehavior.js";
import { StatusResponse } from "#types";
class Endpoints {
  #node;
  constructor(node) {
    this.#node = node;
  }
  get node() {
    return this.#node;
  }
  has(endpoint) {
    if (endpoint === this.#node || endpoint === 0) {
      return true;
    }
    if (typeof endpoint === "number") {
      return endpoint in this.#index;
    }
    if (typeof endpoint === "string") {
      return endpoint in this.#idIndex;
    }
    return endpoint.lifecycle.hasNumber && endpoint.number in this.#index;
  }
  get size() {
    return this.#list.length + 1;
  }
  map(mapper) {
    return this.#list.map(mapper);
  }
  find(predicate) {
    return this.#list.find(predicate);
  }
  filter(predicate) {
    return this.#list.filter(predicate);
  }
  [Symbol.iterator]() {
    return this.#list[Symbol.iterator]();
  }
  for(number) {
    if (number === 0) {
      return this.#node;
    }
    const endpoint = typeof number === "string" ? this.#idIndex[number] : this.#index[number];
    if (endpoint === void 0) {
      throw new StatusResponse.NotFoundError(`Endpoint ${number} does not exist`);
    }
    return endpoint;
  }
  /**
   * Object mapping EndpointNumber -> Endpoint.
   *
   * Note that this does not include endpoint 0, but we have that in #node.
   */
  get #index() {
    return this.#node.behaviors.internalsOf(IndexBehavior).partsByNumber;
  }
  /**
   * Object mapping Endpoint-Id -> Endpoint.
   *
   * Note that this does not include endpoint 0, but we have that in #node.
   */
  get #idIndex() {
    return this.#node.behaviors.internalsOf(IndexBehavior).partsById;
  }
  /**
   * Full list of endpoints.  Includes endpoint 0.
   */
  get #list() {
    return [this.#node, ...Object.values(this.#index)];
  }
}
export {
  Endpoints
};
//# sourceMappingURL=Endpoints.js.map
