/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { MutableCluster } from "../cluster/mutation/MutableCluster.js";
import { WritableAttribute, FixedAttribute } from "../cluster/Cluster.js";
import { TlvEnum } from "../tlv/TlvNumber.js";
import { AccessLevel } from "#model";
import { TlvArray } from "../tlv/TlvArray.js";
import { BitFlag } from "../schema/BitmapSchema.js";
import { ClusterRegistry } from "../cluster/ClusterRegistry.js";
var UnitLocalization;
((UnitLocalization2) => {
  let Feature;
  ((Feature2) => {
    Feature2["TemperatureUnit"] = "TemperatureUnit";
  })(Feature = UnitLocalization2.Feature || (UnitLocalization2.Feature = {}));
  let TempUnit;
  ((TempUnit2) => {
    TempUnit2[TempUnit2["Fahrenheit"] = 0] = "Fahrenheit";
    TempUnit2[TempUnit2["Celsius"] = 1] = "Celsius";
    TempUnit2[TempUnit2["Kelvin"] = 2] = "Kelvin";
  })(TempUnit = UnitLocalization2.TempUnit || (UnitLocalization2.TempUnit = {}));
  UnitLocalization2.TemperatureUnitComponent = MutableCluster.Component({
    attributes: {
      /**
       * Indicates the unit for the Node to use only when conveying temperature in communication to the user, for
       * example such as via a user interface on the device. If provided, this value shall take priority over any
       * unit implied through the ActiveLocale Attribute.
       *
       * An attempt to write to this attribute with a value not included in the SupportedTemperatureUnits
       * attribute list shall result in a CONSTRAINT_ERROR.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.5.6.1
       */
      temperatureUnit: WritableAttribute(
        0,
        TlvEnum(),
        { persistent: true, writeAcl: AccessLevel.Manage }
      ),
      /**
       * Indicates a list of units supported by the Node to be used when writing the TemperatureUnit attribute of
       * this cluster. Each entry in the list shall be unique.
       *
       * @see {@link MatterSpecification.v142.Core} § 11.5.6.2
       */
      supportedTemperatureUnits: FixedAttribute(
        1,
        TlvArray(TlvEnum(), { minLength: 2, maxLength: 3 })
      )
    }
  });
  UnitLocalization2.Base = MutableCluster.Component({
    id: 45,
    name: "UnitLocalization",
    revision: 2,
    features: {
      /**
       * The Node can be configured to use different units of temperature when conveying values to a user.
       */
      temperatureUnit: BitFlag(0)
    },
    /**
     * This metadata controls which UnitLocalizationCluster elements matter.js activates for specific feature
     * combinations.
     */
    extensions: MutableCluster.Extensions({ flags: { temperatureUnit: true }, component: UnitLocalization2.TemperatureUnitComponent })
  });
  UnitLocalization2.ClusterInstance = MutableCluster(UnitLocalization2.Base);
  UnitLocalization2.Cluster = UnitLocalization2.ClusterInstance;
  const TEMP = { temperatureUnit: true };
  UnitLocalization2.CompleteInstance = MutableCluster({
    id: UnitLocalization2.Cluster.id,
    name: UnitLocalization2.Cluster.name,
    revision: UnitLocalization2.Cluster.revision,
    features: UnitLocalization2.Cluster.features,
    attributes: {
      temperatureUnit: MutableCluster.AsConditional(
        UnitLocalization2.TemperatureUnitComponent.attributes.temperatureUnit,
        { mandatoryIf: [TEMP] }
      ),
      supportedTemperatureUnits: MutableCluster.AsConditional(
        UnitLocalization2.TemperatureUnitComponent.attributes.supportedTemperatureUnits,
        { mandatoryIf: [TEMP] }
      )
    }
  });
  UnitLocalization2.Complete = UnitLocalization2.CompleteInstance;
})(UnitLocalization || (UnitLocalization = {}));
const UnitLocalizationCluster = UnitLocalization.Cluster;
ClusterRegistry.register(UnitLocalization.Complete);
export {
  UnitLocalization,
  UnitLocalizationCluster
};
//# sourceMappingURL=unit-localization.js.map
