"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 GroupId_exports = {};
__export(GroupId_exports, {
  GroupId: () => GroupId,
  TlvGroupId: () => TlvGroupId
});
module.exports = __toCommonJS(GroupId_exports);
var import_general = require("#general");
var import_ValidationError = require("../common/ValidationError.js");
var import_TlvNumber = require("../tlv/TlvNumber.js");
var import_TlvWrapper = require("../tlv/TlvWrapper.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function GroupId(groupId, validate = true) {
  if (!validate || groupId >= 0 && groupId <= 65535) {
    return Number(groupId);
  }
  throw new import_ValidationError.ValidationOutOfBoundsError(`Invalid group ID: ${groupId}`);
}
((GroupId2) => {
  GroupId2.NO_GROUP_ID = GroupId2(0);
  GroupId2.ALL_NODES = 65535;
  GroupId2.ALL_NON_ICD_NODES = 65534;
  GroupId2.isValid = (0, import_ValidationError.validatorOf)(GroupId2);
  function isApplicationGroupId(groupId) {
    return groupId >= 1 && groupId <= 65279;
  }
  GroupId2.isApplicationGroupId = isApplicationGroupId;
  function assertGroupId(groupId) {
    if (groupId === GroupId2.NO_GROUP_ID) {
      throw new import_general.UnexpectedDataError(`A Group ID need to be specified and can not be 0`);
    }
  }
  GroupId2.assertGroupId = assertGroupId;
  function fromNodeId(nodeId) {
    if (!(0, GroupId2.isGroupNodeId)(nodeId)) {
      throw new import_general.InternalError(`Node ID ${nodeId} is not a group node ID`);
    }
    const groupId = Number(nodeId & BigInt(65535));
    return GroupId2(groupId);
  }
  GroupId2.fromNodeId = fromNodeId;
  GroupId2.isGroupNodeId = (nodeId) => {
    const nodeIdHex = nodeId.toString(16);
    return nodeIdHex.startsWith("ffffffffffff") && nodeIdHex.length === 16;
  };
})(GroupId || (GroupId = {}));
const TlvGroupId = new import_TlvWrapper.TlvWrapper(
  import_TlvNumber.TlvUInt16,
  (groupId) => groupId,
  (value) => GroupId(value, false)
  // No automatic validation on decode
);
//# sourceMappingURL=GroupId.js.map
