"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 ClusterId_exports = {};
__export(ClusterId_exports, {
  ClusterId: () => ClusterId,
  TlvClusterId: () => TlvClusterId
});
module.exports = __toCommonJS(ClusterId_exports);
var import_ValidationError = require("../common/ValidationError.js");
var import_TlvNumber = require("../tlv/TlvNumber.js");
var import_TlvWrapper = require("../tlv/TlvWrapper.js");
var import_ManufacturerExtensibleIdentifier = require("./ManufacturerExtensibleIdentifier.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function ClusterId(clusterId, validate = true) {
  if (!validate) {
    return clusterId;
  }
  const { vendorPrefix, typeSuffix } = import_ManufacturerExtensibleIdentifier.Mei.fromMei(clusterId);
  if (typeSuffix >= 0 && typeSuffix <= 32767 && vendorPrefix === 0 || // Standard cluster
  typeSuffix >= 64512 && typeSuffix <= 65534 && vendorPrefix !== 0) {
    return clusterId;
  }
  throw new import_ValidationError.ValidationOutOfBoundsError(`Invalid cluster ID: ${clusterId}`);
}
((ClusterId2) => {
  ClusterId2.isVendorSpecific = (clusterId) => {
    try {
      const { vendorPrefix } = import_ManufacturerExtensibleIdentifier.Mei.fromMei(clusterId);
      return vendorPrefix !== 0;
    } catch (e) {
      import_ValidationError.ValidationError.accept(e);
      return false;
    }
  };
  ClusterId2.isValid = (0, import_ValidationError.validatorOf)(ClusterId2);
  ClusterId2.buildVendorSpecific = (vendorPrefix, clusterSuffix) => {
    return ClusterId2(import_ManufacturerExtensibleIdentifier.Mei.asMei(vendorPrefix, clusterSuffix));
  };
})(ClusterId || (ClusterId = {}));
const TlvClusterId = new import_TlvWrapper.TlvWrapper(
  import_TlvNumber.TlvUInt32,
  (clusterId) => clusterId,
  (value) => ClusterId(value, false)
  // No automatic validation on decode
);
//# sourceMappingURL=ClusterId.js.map
