/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { MutableCluster } from "../cluster/mutation/MutableCluster.js";
import {
  Attribute,
  FixedAttribute,
  OptionalAttribute,
  OptionalWritableAttribute,
  OptionalCommand,
  TlvNoResponse
} from "../cluster/Cluster.js";
import { TlvPercent, TlvEnum, TlvEpochS } from "../tlv/TlvNumber.js";
import { TlvArray } from "../tlv/TlvArray.js";
import { TlvField, TlvObject } from "../tlv/TlvObject.js";
import { TlvString } from "../tlv/TlvString.js";
import { BitFlag } from "../schema/BitmapSchema.js";
import { TlvBoolean } from "../tlv/TlvBoolean.js";
import { TlvNullable } from "../tlv/TlvNullable.js";
import { TlvNoArguments } from "../tlv/TlvNoArguments.js";
var ResourceMonitoring;
((ResourceMonitoring2) => {
  let Feature;
  ((Feature2) => {
    Feature2["Condition"] = "Condition";
    Feature2["Warning"] = "Warning";
    Feature2["ReplacementProductList"] = "ReplacementProductList";
  })(Feature = ResourceMonitoring2.Feature || (ResourceMonitoring2.Feature = {}));
  let DegradationDirection;
  ((DegradationDirection2) => {
    DegradationDirection2[DegradationDirection2["Up"] = 0] = "Up";
    DegradationDirection2[DegradationDirection2["Down"] = 1] = "Down";
  })(DegradationDirection = ResourceMonitoring2.DegradationDirection || (ResourceMonitoring2.DegradationDirection = {}));
  let ProductIdentifierType;
  ((ProductIdentifierType2) => {
    ProductIdentifierType2[ProductIdentifierType2["Upc"] = 0] = "Upc";
    ProductIdentifierType2[ProductIdentifierType2["Gtin8"] = 1] = "Gtin8";
    ProductIdentifierType2[ProductIdentifierType2["Ean"] = 2] = "Ean";
    ProductIdentifierType2[ProductIdentifierType2["Gtin14"] = 3] = "Gtin14";
    ProductIdentifierType2[ProductIdentifierType2["Oem"] = 4] = "Oem";
  })(ProductIdentifierType = ResourceMonitoring2.ProductIdentifierType || (ResourceMonitoring2.ProductIdentifierType = {}));
  ResourceMonitoring2.TlvReplacementProduct = TlvObject({
    productIdentifierType: TlvField(0, TlvEnum()),
    productIdentifierValue: TlvField(1, TlvString.bound({ maxLength: 20 }))
  });
  let ChangeIndication;
  ((ChangeIndication2) => {
    ChangeIndication2[ChangeIndication2["Ok"] = 0] = "Ok";
    ChangeIndication2[ChangeIndication2["Warning"] = 1] = "Warning";
    ChangeIndication2[ChangeIndication2["Critical"] = 2] = "Critical";
  })(ChangeIndication = ResourceMonitoring2.ChangeIndication || (ResourceMonitoring2.ChangeIndication = {}));
  ResourceMonitoring2.ConditionComponent = MutableCluster.Component({
    attributes: {
      /**
       * Indicates the current condition of the resource in percent.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 2.8.6.1
       */
      condition: Attribute(0, TlvPercent),
      /**
       * Indicates the direction of change for the condition of the resource over time, which helps to determine
       * whether a higher or lower condition value is considered optimal.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 2.8.6.2
       */
      degradationDirection: FixedAttribute(1, TlvEnum())
    }
  });
  ResourceMonitoring2.ReplacementProductListComponent = MutableCluster.Component({
    attributes: {
      /**
       * Indicates the list of supported products that may be used as replacements for the current resource. Each
       * item in this list represents a unique ReplacementProductStruct.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 2.8.6.6
       */
      replacementProductList: FixedAttribute(
        5,
        TlvArray(ResourceMonitoring2.TlvReplacementProduct, { maxLength: 5 }),
        { default: [] }
      )
    }
  });
  ResourceMonitoring2.Base = MutableCluster.Component({
    features: {
      /**
       * Supports monitoring the condition of the resource in percentage
       */
      condition: BitFlag(0),
      /**
       * Supports warning indication
       */
      warning: BitFlag(1),
      /**
       * Supports specifying the list of replacement products
       */
      replacementProductList: BitFlag(2)
    },
    name: "ResourceMonitoring",
    revision: 1,
    attributes: {
      /**
       * This attribute shall be populated with a value from ChangeIndicationEnum that is indicative of the
       * current requirement to change the resource.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 2.8.6.3
       */
      changeIndication: Attribute(2, TlvEnum()),
      /**
       * Indicates whether a resource is currently installed. A value of true shall indicate that a resource is
       * installed. A value of false shall indicate that a resource is not installed.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 2.8.6.4
       */
      inPlaceIndicator: OptionalAttribute(3, TlvBoolean),
      /**
       * This attribute may indicates the time at which the resource has been changed, if supported by the server.
       * The attribute shall be null if it was never set or is unknown.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 2.8.6.5
       */
      lastChangedTime: OptionalWritableAttribute(
        4,
        TlvNullable(TlvEpochS),
        { persistent: true, default: null }
      )
    },
    commands: {
      /**
       * Upon receipt, the device shall reset the Condition and ChangeIndicator attributes, indicating full
       * resource availability and readiness for use, as initially configured. Invocation of this command may
       * cause the LastChangedTime to be updated automatically based on the clock of the server, if the server
       * supports setting the attribute.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 2.8.7.1
       */
      resetCondition: OptionalCommand(0, TlvNoArguments, 0, TlvNoResponse)
    },
    /**
     * This metadata controls which ResourceMonitoringCluster elements matter.js activates for specific feature
     * combinations.
     */
    extensions: MutableCluster.Extensions(
      { flags: { condition: true }, component: ResourceMonitoring2.ConditionComponent },
      { flags: { replacementProductList: true }, component: ResourceMonitoring2.ReplacementProductListComponent }
    )
  });
  const CON = { condition: true };
  const REP = { replacementProductList: true };
  ResourceMonitoring2.CompleteInstance = MutableCluster.Component({
    name: ResourceMonitoring2.Base.name,
    revision: ResourceMonitoring2.Base.revision,
    features: ResourceMonitoring2.Base.features,
    attributes: {
      ...ResourceMonitoring2.Base.attributes,
      condition: MutableCluster.AsConditional(ResourceMonitoring2.ConditionComponent.attributes.condition, { mandatoryIf: [CON] }),
      degradationDirection: MutableCluster.AsConditional(
        ResourceMonitoring2.ConditionComponent.attributes.degradationDirection,
        { mandatoryIf: [CON] }
      ),
      replacementProductList: MutableCluster.AsConditional(
        ResourceMonitoring2.ReplacementProductListComponent.attributes.replacementProductList,
        { mandatoryIf: [REP] }
      )
    },
    commands: ResourceMonitoring2.Base.commands
  });
  ResourceMonitoring2.Complete = ResourceMonitoring2.CompleteInstance;
})(ResourceMonitoring || (ResourceMonitoring = {}));
export {
  ResourceMonitoring
};
//# sourceMappingURL=resource-monitoring.js.map
