"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 software_diagnostics_exports = {};
__export(software_diagnostics_exports, {
  SoftwareDiagnostics: () => SoftwareDiagnostics,
  SoftwareDiagnosticsCluster: () => SoftwareDiagnosticsCluster
});
module.exports = __toCommonJS(software_diagnostics_exports);
var import_MutableCluster = require("../cluster/mutation/MutableCluster.js");
var import_Cluster = require("../cluster/Cluster.js");
var import_TlvNumber = require("../tlv/TlvNumber.js");
var import_TlvNoArguments = require("../tlv/TlvNoArguments.js");
var import_model = require("@matter/model");
var import_BitmapSchema = require("../schema/BitmapSchema.js");
var import_TlvArray = require("../tlv/TlvArray.js");
var import_TlvObject = require("../tlv/TlvObject.js");
var import_TlvString = require("../tlv/TlvString.js");
var import_Priority = require("../globals/Priority.js");
var import_ClusterRegistry = require("../cluster/ClusterRegistry.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
var SoftwareDiagnostics;
((SoftwareDiagnostics2) => {
  let Feature;
  ((Feature2) => {
    Feature2["Watermarks"] = "Watermarks";
  })(Feature = SoftwareDiagnostics2.Feature || (SoftwareDiagnostics2.Feature = {}));
  SoftwareDiagnostics2.TlvThreadMetrics = (0, import_TlvObject.TlvObject)({
    /**
     * The Id field shall be a server-assigned per-thread unique ID that is constant for the duration of the thread.
     * Efforts SHOULD be made to avoid reusing ID values when possible.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.13.5.1.1
     */
    id: (0, import_TlvObject.TlvField)(0, import_TlvNumber.TlvUInt64),
    /**
     * The Name field shall be set to a vendor defined name or prefix of the software thread that is static for the
     * duration of the thread.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.13.5.1.2
     */
    name: (0, import_TlvObject.TlvOptionalField)(1, import_TlvString.TlvString.bound({ maxLength: 8 })),
    /**
     * The StackFreeCurrent field shall indicate the current amount of stack memory, in bytes, that are not being
     * utilized on the respective thread.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.13.5.1.3
     */
    stackFreeCurrent: (0, import_TlvObject.TlvOptionalField)(2, import_TlvNumber.TlvUInt32),
    /**
     * The StackFreeMinimum field shall indicate the minimum amount of stack memory, in bytes, that has been
     * available at any point between the current time and this attribute being reset or initialized on the
     * respective thread. This value shall only be reset upon a Node reboot or upon receiving of the ResetWatermarks
     * command.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.13.5.1.4
     */
    stackFreeMinimum: (0, import_TlvObject.TlvOptionalField)(3, import_TlvNumber.TlvUInt32),
    /**
     * The StackSize field shall indicate the amount of stack memory, in bytes, that has been allocated for use by
     * the respective thread.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.13.5.1.5
     */
    stackSize: (0, import_TlvObject.TlvOptionalField)(4, import_TlvNumber.TlvUInt32)
  });
  SoftwareDiagnostics2.TlvSoftwareFaultEvent = (0, import_TlvObject.TlvObject)({
    /**
     * This field shall be set to the ID of the software thread in which the last software fault occurred.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.13.8.1.1
     */
    id: (0, import_TlvObject.TlvField)(0, import_TlvNumber.TlvUInt64),
    /**
     * This field shall be set to a manufacturer-specified name or prefix of the software thread in which the last
     * software fault occurred.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.13.8.1.2
     */
    name: (0, import_TlvObject.TlvOptionalField)(1, import_TlvString.TlvString.bound({ maxLength: 8 })),
    /**
     * This field shall be a manufacturer-specified payload intended to convey information to assist in further
     * diagnosing or debugging a software fault. The FaultRecording field may be used to convey information such as,
     * but not limited to, thread backtraces or register contents.
     *
     * @see {@link MatterSpecification.v142.Core} § 11.13.8.1.3
     */
    faultRecording: (0, import_TlvObject.TlvOptionalField)(2, import_TlvString.TlvByteString.bound({ maxLength: 1024 }))
  });
  SoftwareDiagnostics2.WatermarksComponent = import_MutableCluster.MutableCluster.Component({
    attributes: {
      /**
       * Indicates the maximum amount of heap memory, in bytes, that has been used by the Node. This value shall
       * only be reset upon a Node reboot or upon receiving of the ResetWatermarks command.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.13.6.4
       */
      currentHeapHighWatermark: (0, import_Cluster.Attribute)(3, import_TlvNumber.TlvUInt64)
    },
    commands: {
      /**
       * This command is used to reset the high watermarks for heap and stack memory.
       *
       * Receipt of this command shall reset the following values which track high and lower watermarks:
       *
       *   - The StackFreeMinimum field of the ThreadMetrics attribute
       *
       *   - The CurrentHeapHighWatermark attribute
       *
       * ### Effect on Receipt
       *
       * On receipt of this command, the Node shall make the following modifications to attributes it supports:
       *
       * If implemented, the server shall set the value of the CurrentHeapHighWatermark attribute to the value of
       * the CurrentHeapUsed attribute.
       *
       * If implemented, the server shall set the value of the StackFreeMinimum field for every thread to the
       * value of the corresponding thread’s StackFreeCurrent field.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.13.7.1
       */
      resetWatermarks: (0, import_Cluster.Command)(0, import_TlvNoArguments.TlvNoArguments, 0, import_Cluster.TlvNoResponse, { invokeAcl: import_model.AccessLevel.Manage })
    }
  });
  SoftwareDiagnostics2.Base = import_MutableCluster.MutableCluster.Component({
    id: 52,
    name: "SoftwareDiagnostics",
    revision: 1,
    features: {
      /**
       * Node makes available the metrics for high watermark related to memory consumption.
       */
      watermarks: (0, import_BitmapSchema.BitFlag)(0)
    },
    attributes: {
      /**
       * This attribute shall be a list of ThreadMetricsStruct structs. Each active thread on the Node shall be
       * represented by a single entry within the ThreadMetrics attribute.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.13.6.1
       */
      threadMetrics: (0, import_Cluster.OptionalAttribute)(0, (0, import_TlvArray.TlvArray)(SoftwareDiagnostics2.TlvThreadMetrics, { maxLength: 64 }), { default: [] }),
      /**
       * Indicates the current amount of heap memory, in bytes, that are free for allocation. The effective amount
       * may be smaller due to heap fragmentation or other reasons.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.13.6.2
       */
      currentHeapFree: (0, import_Cluster.OptionalAttribute)(1, import_TlvNumber.TlvUInt64),
      /**
       * Indicates the current amount of heap memory, in bytes, that is being used.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.13.6.3
       */
      currentHeapUsed: (0, import_Cluster.OptionalAttribute)(2, import_TlvNumber.TlvUInt64)
    },
    events: {
      /**
       * This Event shall be generated when a software fault occurs on the Node.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.13.8.1
       */
      softwareFault: (0, import_Cluster.OptionalEvent)(0, import_Priority.Priority.Info, SoftwareDiagnostics2.TlvSoftwareFaultEvent)
    },
    /**
     * This metadata controls which SoftwareDiagnosticsCluster elements matter.js activates for specific feature
     * combinations.
     */
    extensions: import_MutableCluster.MutableCluster.Extensions({ flags: { watermarks: true }, component: SoftwareDiagnostics2.WatermarksComponent })
  });
  SoftwareDiagnostics2.ClusterInstance = (0, import_MutableCluster.MutableCluster)(SoftwareDiagnostics2.Base);
  SoftwareDiagnostics2.Cluster = SoftwareDiagnostics2.ClusterInstance;
  const WTRMRK = { watermarks: true };
  SoftwareDiagnostics2.CompleteInstance = (0, import_MutableCluster.MutableCluster)({
    id: SoftwareDiagnostics2.Cluster.id,
    name: SoftwareDiagnostics2.Cluster.name,
    revision: SoftwareDiagnostics2.Cluster.revision,
    features: SoftwareDiagnostics2.Cluster.features,
    attributes: {
      ...SoftwareDiagnostics2.Cluster.attributes,
      currentHeapHighWatermark: import_MutableCluster.MutableCluster.AsConditional(
        SoftwareDiagnostics2.WatermarksComponent.attributes.currentHeapHighWatermark,
        { mandatoryIf: [WTRMRK] }
      )
    },
    commands: {
      resetWatermarks: import_MutableCluster.MutableCluster.AsConditional(
        SoftwareDiagnostics2.WatermarksComponent.commands.resetWatermarks,
        { mandatoryIf: [WTRMRK] }
      )
    },
    events: SoftwareDiagnostics2.Cluster.events
  });
  SoftwareDiagnostics2.Complete = SoftwareDiagnostics2.CompleteInstance;
})(SoftwareDiagnostics || (SoftwareDiagnostics = {}));
const SoftwareDiagnosticsCluster = SoftwareDiagnostics.Cluster;
import_ClusterRegistry.ClusterRegistry.register(SoftwareDiagnostics.Complete);
//# sourceMappingURL=software-diagnostics.js.map
