"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 IdentityService_exports = {};
__export(IdentityService_exports, {
  IdentityConflictError: () => IdentityConflictError,
  IdentityService: () => IdentityService
});
module.exports = __toCommonJS(IdentityService_exports);
var import_LocalActorContext = require("#behavior/context/server/LocalActorContext.js");
var import_IndexBehavior = require("#behavior/system/index/IndexBehavior.js");
var import_general = require("#general");
/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class IdentityConflictError extends import_general.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(import_LocalActorContext.LocalActorContext.ReadOnly).get(import_IndexBehavior.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 import_general.InternalError("Client node ID assignment is not initialized");
  }
  /**
   * Release a peer address.
   */
  releaseNodeAddress(_address) {
  }
}
//# sourceMappingURL=IdentityService.js.map
