/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Logger } from "#general";
import { ValidationOutOfBoundsError } from "../common/ValidationError.js";
import { TlvUInt32 } from "../tlv/TlvNumber.js";
import { TlvWrapper } from "../tlv/TlvWrapper.js";
const logger = Logger.get("CaseAuthenticatedTag");
function CaseAuthenticatedTag(idOrTag, version) {
  if (version !== void 0) {
    idOrTag = idOrTag << 16 | version;
  }
  if ((idOrTag & 65535) === 0) {
    throw new ValidationOutOfBoundsError("CaseAuthenticatedTag version number must not be 0.");
  }
  if (idOrTag >>> 16 > 61439) {
    logger.warn(
      `CaseAuthenticatedTag Identifier 0x${(idOrTag >>> 16).toString(16).toUpperCase()} SHOULD NOT exceed 0xEFFF. Please choose a lower value.`
    );
  }
  return idOrTag;
}
((CaseAuthenticatedTag2) => {
  CaseAuthenticatedTag2.AdministratorIdentifier = (version = 1) => {
    if (version <= 0 || version > 65535) {
      throw new ValidationOutOfBoundsError("CaseAuthenticatedTag version number must be between 1 and 0xffff.");
    }
    return 65533 << 16 | version;
  };
  CaseAuthenticatedTag2.AnchorIdentifier = (version = 1) => {
    if (version <= 0 || version > 65535) {
      throw new ValidationOutOfBoundsError("CaseAuthenticatedTag version number must be between 1 and 0xffff.");
    }
    return 65534 << 16 | version;
  };
  CaseAuthenticatedTag2.getIdentifyValue = (tag) => tag >>> 16;
  CaseAuthenticatedTag2.getVersion = (tag) => tag & 65535;
  CaseAuthenticatedTag2.increaseVersion = (tag) => {
    const version = (0, CaseAuthenticatedTag2.getVersion)(tag);
    if (version === 65535) {
      throw new ValidationOutOfBoundsError("CaseAuthenticatedTag version number must not exceed 0xffff.");
    }
    return CaseAuthenticatedTag2(tag + 1);
  };
  CaseAuthenticatedTag2.validateNocTagList = (tags) => {
    if (tags.length > 3) {
      throw new ValidationOutOfBoundsError(`Too many CaseAuthenticatedTags (${tags.length}).`);
    }
    const tagIdentifierValues = new Set(tags.map((cat) => CaseAuthenticatedTag2.getIdentifyValue(cat)));
    if (tagIdentifierValues.size !== tags.length) {
      throw new ValidationOutOfBoundsError("CASEAuthenticatedTags field contains duplicate identifier values.");
    }
  };
})(CaseAuthenticatedTag || (CaseAuthenticatedTag = {}));
class TlvCaseAuthenticatedTagSchema extends TlvWrapper {
  constructor() {
    super(
      TlvUInt32,
      (caseAuthenticatedTag) => caseAuthenticatedTag,
      (value) => CaseAuthenticatedTag(value)
    );
  }
  validate(value) {
    super.validate(value);
    if ((value & 65535) === 0) {
      throw new ValidationOutOfBoundsError("CaseAuthenticatedTag version number must not be 0.");
    }
  }
}
const TlvCaseAuthenticatedTag = new TlvCaseAuthenticatedTagSchema();
export {
  CaseAuthenticatedTag,
  TlvCaseAuthenticatedTag
};
//# sourceMappingURL=CaseAuthenticatedTag.js.map
