"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 Device_exports = {};
__export(Device_exports, {
  Device: () => Device,
  PairedDevice: () => PairedDevice,
  RootEndpoint: () => RootEndpoint
});
module.exports = __toCommonJS(Device_exports);
var import_general = require("@matter/general");
var import_model = require("@matter/model");
var import_types = require("@matter/types");
var import_DeviceTypes = require("./DeviceTypes.js");
var import_Endpoint = require("./Endpoint.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class PairedDevice extends import_Endpoint.Endpoint {
  /**
   * Create a new PairedDevice instance. All data are automatically parsed from the paired device!
   *
   * @param endpoint Underlying ClientEndpoint instance
   * @param definition DeviceTypeDefinitions of the paired device as reported by the device
   * @param clusters Clusters of the paired device as reported by the device
   * @param endpointId Endpoint ID of the paired device as reported by the device
   */
  constructor(endpoint, definition, clusters = [], endpointId) {
    super(endpoint, definition, { endpointId });
    clusters.forEach((cluster) => {
      this.addClusterClient(cluster);
    });
  }
}
class RootEndpoint extends import_Endpoint.Endpoint {
  /**
   * Create a new RootEndpoint instance. This is automatically instanced by the CommissioningServer class.
   */
  constructor(endpoint) {
    super(endpoint, [(0, import_DeviceTypes.getDeviceTypeDefinitionFromModelByCode)(import_model.RootNodeDt.id)], { endpointId: (0, import_types.EndpointNumber)(0) });
  }
  /**
   * Add a cluster client to the root endpoint. This is mainly used internally and not needed to be called by the user.
   *
   * @param cluster ClusterClient object to add
   */
  addRootClusterClient(cluster) {
    this.addClusterClient(cluster);
  }
  getRootClusterClient(cluster) {
    return this.getClusterClient(cluster);
  }
}
class Device extends import_Endpoint.Endpoint {
  commandHandler = new import_general.NamedHandler();
  /**
   * Create a new Device instance.
   *
   * @param endpoint Underlying ClientEndpoint instance
   * @param definition DeviceTypeDefinitions of the device
   * @param options Optional endpoint options
   */
  constructor(endpoint, definition, options = {}) {
    if (definition.deviceClass === import_DeviceTypes.DeviceClasses.Node) {
      throw new import_general.NotImplementedError("MatterNode devices are not supported");
    }
    super(endpoint, [definition], options);
  }
  /**
   * Method to add command handlers to the device.
   * The base class do not expose any commands!
   *
   * @param command Command name to add a handler for
   * @param handler Handler function to be executed when the command is received
   */
  addCommandHandler(command, handler) {
    this.commandHandler.addHandler(command, handler);
  }
  /**
   * Method to remove command handlers from the device.
   * The base class do not expose any commands!
   *
   * @param command Command name to remove the handler from
   * @param handler Handler function to be removed
   */
  removeCommandHandler(command, handler) {
    this.commandHandler.removeHandler(command, handler);
  }
  /**
   * Execute a command handler. Should only be used internally, but cannot be declared as protected officially
   * because needed public for derived classes.
   *
   * @protected
   * @param command Command name to execute the handler for
   * @param args Arguments to be passed to the handler
   */
  async _executeHandler(command, ...args) {
    return await this.commandHandler.executeHandler(command, ...args);
  }
}
//# sourceMappingURL=Device.js.map
