/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { MutableCluster } from "../cluster/mutation/MutableCluster.js";
import { Attribute, FixedAttribute, Command, TlvNoResponse } from "../cluster/Cluster.js";
import { TlvInt16, TlvUInt8 } from "../tlv/TlvNumber.js";
import { TlvArray } from "../tlv/TlvArray.js";
import { TlvString } from "../tlv/TlvString.js";
import { BitFlag } from "../schema/BitmapSchema.js";
import { TlvOptionalField, TlvObject } from "../tlv/TlvObject.js";
import { ClusterRegistry } from "../cluster/ClusterRegistry.js";
var TemperatureControl;
((TemperatureControl2) => {
  let Feature;
  ((Feature2) => {
    Feature2["TemperatureNumber"] = "TemperatureNumber";
    Feature2["TemperatureLevel"] = "TemperatureLevel";
    Feature2["TemperatureStep"] = "TemperatureStep";
  })(Feature = TemperatureControl2.Feature || (TemperatureControl2.Feature = {}));
  TemperatureControl2.TlvSetTemperatureRequest = TlvObject({
    /**
     * This field shall specify the desired temperature setpoint that the server is to be set to.
     *
     * The TargetTemperature shall be from MinTemperature to MaxTemperature inclusive. If the Step attribute is
     * supported, TargetTemperature shall be such that (TargetTemperature - MinTemperature) % Step == 0.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 8.2.6.1.1
     */
    targetTemperature: TlvOptionalField(0, TlvInt16),
    /**
     * This field shall specify the index of the list item in the SupportedTemperatureLevels list that represents
     * the desired temperature level setting of the server. The value of this field shall be between 0 and the
     * length of the SupportedTemperatureLevels list -1.
     *
     * @see {@link MatterSpecification.v142.Cluster} § 8.2.6.1.2
     */
    targetTemperatureLevel: TlvOptionalField(1, TlvUInt8)
  });
  TemperatureControl2.TemperatureNumberComponent = MutableCluster.Component({
    attributes: {
      /**
       * Indicates the desired Temperature Setpoint on the device.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 8.2.5.1
       */
      temperatureSetpoint: Attribute(0, TlvInt16),
      /**
       * Indicates the minimum temperature to which the TemperatureSetpoint attribute may be set.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 8.2.5.2
       */
      minTemperature: FixedAttribute(1, TlvInt16),
      /**
       * Indicates the maximum temperature to which the TemperatureSetpoint attribute may be set.
       *
       * If the Step attribute is supported, this attribute shall be such that MaxTemperature = MinTemperature +
       * (Step * n), where n is an integer and n > 0. If the Step attribute is not supported, this attribute shall
       * be such that MaxTemperature > MinTemperature.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 8.2.5.3
       */
      maxTemperature: FixedAttribute(2, TlvInt16)
    }
  });
  TemperatureControl2.TemperatureStepComponent = MutableCluster.Component({
    attributes: {
      /**
       * Indicates the discrete value by which the TemperatureSetpoint attribute can be changed via the
       * SetTemperature command.
       *
       * For example, if the value of MinTemperature is 25.00C (2500) and the Step value is 0.50C (50), valid
       * values of the TargetTemperature field of the SetTemperature command would be 25.50C
       *
       * (2550), 26.00C (2600), 26.50C (2650), etc.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 8.2.5.4
       */
      step: FixedAttribute(3, TlvInt16.bound({ min: 1 }))
    }
  });
  TemperatureControl2.TemperatureLevelComponent = MutableCluster.Component({
    attributes: {
      /**
       * Indicates the currently selected temperature level setting of the server. This attribute shall be the
       * positional index of the list item in the SupportedTemperatureLevels list that represents the currently
       * selected temperature level setting of the server.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 8.2.5.5
       */
      selectedTemperatureLevel: Attribute(4, TlvUInt8.bound({ max: 31 })),
      /**
       * Indicates the list of supported temperature level settings that may be selected via the
       * TargetTemperatureLevel field in the SetTemperature command. Each string is readable text that describes
       * each temperature level setting in a way that can be easily understood by humans. For example, a washing
       * machine can have temperature levels like "Cold", "Warm", and "Hot". Each string is specified by the
       * manufacturer.
       *
       * Each item in this list shall represent a unique temperature level. Each entry in this list shall have a
       * unique value. The entries in this list shall appear in order of increasing temperature level with list
       * item 0 being the setting with the lowest temperature level.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 8.2.5.6
       */
      supportedTemperatureLevels: Attribute(5, TlvArray(TlvString, { maxLength: 32 }), { default: [] })
    }
  });
  TemperatureControl2.Base = MutableCluster.Component({
    id: 86,
    name: "TemperatureControl",
    revision: 1,
    features: {
      /**
       * For devices that use an actual temperature value for the temperature setpoint, such as some water
       * heaters, the feature TN shall be used. Note that this cluster provides and supports temperatures in
       * degrees Celsius via the temperature data type.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 8.2.4.1
       */
      temperatureNumber: BitFlag(0),
      /**
       * For devices that use vendor-specific temperature levels for the temperature setpoint, such as some
       * washers, the feature TL shall be used.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 8.2.4.2
       */
      temperatureLevel: BitFlag(1),
      /**
       * For devices that support discrete temperature setpoints that are larger than the temperature resolution
       * imposed via the temperature data type, the Step feature may be used.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 8.2.4.3
       */
      temperatureStep: BitFlag(2)
    },
    commands: {
      /**
       * This command is used to set the temperature setpoint.
       *
       * @see {@link MatterSpecification.v142.Cluster} § 8.2.6.1
       */
      setTemperature: Command(0, TemperatureControl2.TlvSetTemperatureRequest, 0, TlvNoResponse)
    },
    /**
     * This metadata controls which TemperatureControlCluster elements matter.js activates for specific feature
     * combinations.
     */
    extensions: MutableCluster.Extensions(
      { flags: { temperatureNumber: true }, component: TemperatureControl2.TemperatureNumberComponent },
      { flags: { temperatureStep: true }, component: TemperatureControl2.TemperatureStepComponent },
      { flags: { temperatureLevel: true }, component: TemperatureControl2.TemperatureLevelComponent },
      { flags: { temperatureStep: true, temperatureNumber: false }, component: false },
      { flags: { temperatureNumber: true, temperatureLevel: true }, component: false },
      { flags: { temperatureNumber: false, temperatureLevel: false }, component: false }
    )
  });
  TemperatureControl2.ClusterInstance = MutableCluster.ExtensibleOnly(TemperatureControl2.Base);
  TemperatureControl2.Cluster = TemperatureControl2.ClusterInstance;
  const TN = { temperatureNumber: true };
  const STEP = { temperatureStep: true };
  const TL = { temperatureLevel: true };
  TemperatureControl2.CompleteInstance = MutableCluster({
    id: TemperatureControl2.Base.id,
    name: TemperatureControl2.Base.name,
    revision: TemperatureControl2.Base.revision,
    features: TemperatureControl2.Base.features,
    attributes: {
      temperatureSetpoint: MutableCluster.AsConditional(
        TemperatureControl2.TemperatureNumberComponent.attributes.temperatureSetpoint,
        { mandatoryIf: [TN] }
      ),
      minTemperature: MutableCluster.AsConditional(
        TemperatureControl2.TemperatureNumberComponent.attributes.minTemperature,
        { mandatoryIf: [TN] }
      ),
      maxTemperature: MutableCluster.AsConditional(
        TemperatureControl2.TemperatureNumberComponent.attributes.maxTemperature,
        { mandatoryIf: [TN] }
      ),
      step: MutableCluster.AsConditional(TemperatureControl2.TemperatureStepComponent.attributes.step, { mandatoryIf: [STEP] }),
      selectedTemperatureLevel: MutableCluster.AsConditional(
        TemperatureControl2.TemperatureLevelComponent.attributes.selectedTemperatureLevel,
        { mandatoryIf: [TL] }
      ),
      supportedTemperatureLevels: MutableCluster.AsConditional(
        TemperatureControl2.TemperatureLevelComponent.attributes.supportedTemperatureLevels,
        { mandatoryIf: [TL] }
      )
    },
    commands: TemperatureControl2.Base.commands
  });
  TemperatureControl2.Complete = TemperatureControl2.CompleteInstance;
})(TemperatureControl || (TemperatureControl = {}));
const TemperatureControlCluster = TemperatureControl.Cluster;
ClusterRegistry.register(TemperatureControl.Complete);
export {
  TemperatureControl,
  TemperatureControlCluster
};
//# sourceMappingURL=temperature-control.js.map
