"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Endpoints_exports = {};
__export(Endpoints_exports, {
  Endpoints: () => Endpoints
});
module.exports = __toCommonJS(Endpoints_exports);
var import_IndexBehavior = require("#behavior/system/index/IndexBehavior.js");
var import_types = require("@matter/types");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
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(id) {
    if (id === 0) {
      return this.#node;
    }
    const endpoint = typeof id === "string" ? this.#idIndex[id] : this.#index[id];
    if (endpoint === void 0) {
      throw new import_types.StatusResponse.NotFoundError(`Endpoint ${id} 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(import_IndexBehavior.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(import_IndexBehavior.IndexBehavior).partsById;
  }
  /**
   * Full list of endpoints.  Includes endpoint 0.
   */
  get #list() {
    return [this.#node, ...Object.values(this.#index)];
  }
}
//# sourceMappingURL=Endpoints.js.map
