"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 thread_network_directory_exports = {};
__export(thread_network_directory_exports, {
  ThreadNetworkDirectory: () => ThreadNetworkDirectory,
  ThreadNetworkDirectoryCluster: () => ThreadNetworkDirectoryCluster
});
module.exports = __toCommonJS(thread_network_directory_exports);
var import_MutableCluster = require("../cluster/mutation/MutableCluster.js");
var import_Cluster = require("../cluster/Cluster.js");
var import_TlvString = require("../tlv/TlvString.js");
var import_TlvNullable = require("../tlv/TlvNullable.js");
var import_model = require("#model");
var import_TlvArray = require("../tlv/TlvArray.js");
var import_TlvObject = require("../tlv/TlvObject.js");
var import_TlvNumber = require("../tlv/TlvNumber.js");
var import_ClusterRegistry = require("../cluster/ClusterRegistry.js");
/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
var ThreadNetworkDirectory;
((ThreadNetworkDirectory2) => {
  ThreadNetworkDirectory2.TlvThreadNetwork = (0, import_TlvObject.TlvObject)({
    /**
     * This field shall indicate the Extended PAN ID from the OperationalDataset for the given Thread network.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 10.4.4.1.1
     */
    extendedPanId: (0, import_TlvObject.TlvField)(0, import_TlvString.TlvByteString.bound({ length: 8 })),
    /**
     * This field shall indicate the Network Name from the OperationalDataset for the given Thread network.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 10.4.4.1.2
     */
    networkName: (0, import_TlvObject.TlvField)(1, import_TlvString.TlvString.bound({ minLength: 1, maxLength: 16 })),
    /**
     * This field shall indicate the Channel from the OperationalDataset for the given Thread network.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 10.4.4.1.3
     */
    channel: (0, import_TlvObject.TlvField)(2, import_TlvNumber.TlvUInt16),
    /**
     * This field shall indicate the Active Timestamp from the OperationalDataset for the given Thread network.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 10.4.4.1.4
     */
    activeTimestamp: (0, import_TlvObject.TlvField)(3, import_TlvNumber.TlvUInt64)
  });
  ThreadNetworkDirectory2.TlvAddNetworkRequest = (0, import_TlvObject.TlvObject)({
    /**
     * This field shall represent the Operational Dataset for the network, using the encoding defined in the Thread
     * specification. It shall contain at least the following sub-TLVs: Active Timestamp, Channel, Channel Mask,
     * Extended PAN ID, Network Key, Network Mesh-Local Prefix, Network Name, PAN ID, PSKc, and Security Policy.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 10.4.6.1.1
     */
    operationalDataset: (0, import_TlvObject.TlvField)(0, import_TlvString.TlvByteString.bound({ maxLength: 254 }))
  });
  ThreadNetworkDirectory2.TlvRemoveNetworkRequest = (0, import_TlvObject.TlvObject)({ extendedPanId: (0, import_TlvObject.TlvField)(0, import_TlvString.TlvByteString.bound({ length: 8 })) });
  ThreadNetworkDirectory2.TlvGetOperationalDatasetRequest = (0, import_TlvObject.TlvObject)({
    extendedPanId: (0, import_TlvObject.TlvField)(0, import_TlvString.TlvByteString.bound({ length: 8 }))
  });
  ThreadNetworkDirectory2.TlvOperationalDatasetResponse = (0, import_TlvObject.TlvObject)({
    operationalDataset: (0, import_TlvObject.TlvField)(0, import_TlvString.TlvByteString.bound({ maxLength: 254 }))
  });
  ThreadNetworkDirectory2.ClusterInstance = (0, import_MutableCluster.MutableCluster)({
    id: 1107,
    name: "ThreadNetworkDirectory",
    revision: 1,
    attributes: {
      /**
       * Indicates the Thread Extended PAN ID value for the Thread network designated by the user to be their
       * preferred network for commissioning of Thread devices. If not null, the value of this attribute shall
       * match the ExtendedPanID of a network in the ThreadNetworks attribute. A write operation with a non-null
       * value that does not match any network in the ThreadNetworks list shall be rejected with a status of
       * CONSTRAINT_ERROR.
       *
       * The purpose of designating one Thread network as preferred is to help a commissioner to select a Thread
       * network when a Thread device is within suitable range of more than one Thread network which appears in
       * the ThreadNetworks list. A value of null indicates that there is no current preferred network: All
       * networks may be treated as equally preferred by a commissioner with access to this cluster.
       *
       * This attribute may be automatically set to the ExtendedPanID of the first Thread network added to the
       * ThreadNetworks list.
       *
       * A client shall obtain user consent before changing the value of this attribute from a non-null value.
       *
       * On a factory reset this attribute shall be reset to null.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 10.4.5.1
       */
      preferredExtendedPanId: (0, import_Cluster.WritableAttribute)(
        0,
        (0, import_TlvNullable.TlvNullable)(import_TlvString.TlvByteString.bound({ length: 8 })),
        { persistent: true, writeAcl: import_model.AccessLevel.Manage }
      ),
      /**
       * Indicates the list of Thread Networks known about by this cluster. If the node hosting this cluster
       * includes a Thread Border Router, then an entry for its Thread Network shall be included in this list.
       *
       * The list can be modified via the AddNetwork and RemoveNetwork commands.
       *
       * For each entry in the list, the cluster server also stores a Thread Operational Dataset. Clients use the
       * GetOperationalDataset command to obtain the Operational Dataset for an entry in this list.
       *
       * On a factory reset this list shall be cleared, and any Thread Operational datasets previously stored
       * shall be removed from the Node.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 10.4.5.2
       */
      threadNetworks: (0, import_Cluster.Attribute)(1, (0, import_TlvArray.TlvArray)(ThreadNetworkDirectory2.TlvThreadNetwork), { persistent: true, default: [] }),
      /**
       * Indicates the maximum number of entries that can be held in the ThreadNetworks list; it shall be at least
       * 2 times the number of SupportedFabrics advertised in the Operational Credentials Cluster on the root
       * endpoint of this node.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 10.4.5.3
       */
      threadNetworkTableSize: (0, import_Cluster.FixedAttribute)(2, import_TlvNumber.TlvUInt8)
    },
    commands: {
      /**
       * Adds an entry to the ThreadNetworks attribute with the specified Thread Operational Dataset.
       *
       * If there is an existing entry with the Extended PAN ID then the Thread Operational Dataset for that entry
       * is replaced. As a result, changes to the network parameters (e.g. Channel, Network Name, PSKc, …) of an
       * existing entry with a given Extended PAN ID can be made using this command.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 10.4.6.1
       */
      addNetwork: (0, import_Cluster.Command)(
        0,
        ThreadNetworkDirectory2.TlvAddNetworkRequest,
        0,
        import_Cluster.TlvNoResponse,
        { invokeAcl: import_model.AccessLevel.Manage, timed: true }
      ),
      /**
       * Removes the network with the given Extended PAN ID from the ThreadNetworks attribute.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 10.4.6.2
       */
      removeNetwork: (0, import_Cluster.Command)(
        1,
        ThreadNetworkDirectory2.TlvRemoveNetworkRequest,
        1,
        import_Cluster.TlvNoResponse,
        { invokeAcl: import_model.AccessLevel.Manage, timed: true }
      ),
      /**
       * Retrieves the Thread Operational Dataset with the given Extended PAN ID.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 10.4.6.3
       */
      getOperationalDataset: (0, import_Cluster.Command)(
        2,
        ThreadNetworkDirectory2.TlvGetOperationalDatasetRequest,
        3,
        ThreadNetworkDirectory2.TlvOperationalDatasetResponse,
        { invokeAcl: import_model.AccessLevel.Manage }
      )
    }
  });
  ThreadNetworkDirectory2.Cluster = ThreadNetworkDirectory2.ClusterInstance;
  ThreadNetworkDirectory2.Complete = ThreadNetworkDirectory2.Cluster;
})(ThreadNetworkDirectory || (ThreadNetworkDirectory = {}));
const ThreadNetworkDirectoryCluster = ThreadNetworkDirectory.Cluster;
import_ClusterRegistry.ClusterRegistry.register(ThreadNetworkDirectory.Complete);
//# sourceMappingURL=thread-network-directory.js.map
