/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { ValidationOutOfBoundsError, validatorOf } from "../common/ValidationError.js";
import { TlvUInt32 } from "../tlv/TlvNumber.js";
import { TlvWrapper } from "../tlv/TlvWrapper.js";
import { Mei } from "./ManufacturerExtensibleIdentifier.js";
function FieldId(fieldId, validate = true) {
  if (!validate) {
    return fieldId;
  }
  if (fieldId >= 224 && fieldId <= 254) {
    return fieldId;
  }
  const { typeSuffix } = Mei.fromMei(fieldId);
  if (typeSuffix >= 0 && typeSuffix <= 223) {
    return fieldId;
  }
  throw new ValidationOutOfBoundsError(`Invalid field ID: ${fieldId}`);
}
((FieldId2) => {
  FieldId2.isGlobal = (fieldId) => {
    return fieldId >= 224 && fieldId <= 254;
  };
  FieldId2.isValid = validatorOf(FieldId2);
})(FieldId || (FieldId = {}));
const TlvFieldId = new TlvWrapper(
  TlvUInt32,
  (fieldId) => fieldId,
  (value) => FieldId(value, false)
  // No automatic validation on decode
);
export {
  FieldId,
  TlvFieldId
};
//# sourceMappingURL=FieldId.js.map
