/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { LocalActorContext } from "#behavior/context/server/LocalActorContext.js";
import { IndexBehavior } from "#behavior/system/index/IndexBehavior.js";
import { ImplementationError, InternalError } from "#general";
class IdentityConflictError extends ImplementationError {
}
class IdentityService {
  #partsById;
  #node;
  constructor(node) {
    this.#node = node;
  }
  /**
   * Textual description of the node.
   */
  get nodeDescription() {
    return this.#node.toString();
  }
  /**
   * Ensure that a number is available for assignment to a {@link Endpoint}.
   */
  assertNumberAvailable(number, endpoint) {
    let other;
    if (this.#node.lifecycle.hasNumber && this.#node.number === number) {
      other = this.#node;
    } else {
      if (this.#partsById === void 0) {
        this.#partsById = this.#node.agentFor(LocalActorContext.ReadOnly).get(IndexBehavior).partsById;
      }
      other = this.#partsById?.[number];
    }
    if (other && other !== endpoint) {
      let owner;
      if (other.lifecycle.hasId) {
        owner = `endpoint ${other.id}`;
      } else {
        owner = `another endpoint`;
      }
      throw new IdentityConflictError(`Endpoint number ${number} is already assigned to ${owner}`);
    }
  }
  /**
   * Assign a peer address.
   */
  assignNodeAddress(_node, _fabricIndex, _nodeId) {
    throw new InternalError("Client node ID assignment is not initialized");
  }
  /**
   * Release a peer address.
   */
  releaseNodeAddress(_address) {
  }
}
export {
  IdentityConflictError,
  IdentityService
};
//# sourceMappingURL=IdentityService.js.map
