/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Status } from "#globals/Status.js";
import { StatusResponseError } from "./StatusResponseError.js";
class ValidationError extends StatusResponseError {
  constructor(message, fieldName, errorCode = Status.ConstraintError) {
    super(message, errorCode);
    this.fieldName = fieldName;
    this.message = `(${this.constructor.name}/${this.code}) ${message}`;
  }
}
class ValidationOutOfBoundsError extends ValidationError {
}
class ValidationDatatypeMismatchError extends ValidationError {
  constructor(message, fieldName) {
    super(message, fieldName, Status.InvalidAction);
  }
}
class ValidationMandatoryFieldMissingError extends ValidationError {
  constructor(message, fieldName) {
    super(message, fieldName, Status.InvalidAction);
  }
}
function validatorOf(test) {
  return (...a) => {
    try {
      test(...a);
      return true;
    } catch (e) {
      ValidationError.accept(e);
      return false;
    }
  };
}
export {
  ValidationDatatypeMismatchError,
  ValidationError,
  ValidationMandatoryFieldMissingError,
  ValidationOutOfBoundsError,
  validatorOf
};
//# sourceMappingURL=ValidationError.js.map
