/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { Status, StatusResponseError } from "#types";
import { SchemaImplementationError } from "#model";
class SchemaViolationError extends StatusResponseError {
  constructor(prefix, path, message, code) {
    const text = `${prefix} ${path.path ?? path}: ${message} (${code})`;
    super(text, code);
    this.message = text;
  }
}
class ReadError extends SchemaViolationError {
  constructor(path, message, code) {
    super("Reading", path, message, code ?? Status.UnsupportedRead);
  }
}
class WriteError extends SchemaViolationError {
  constructor(path, message, code) {
    super("Writing", path, message, code ?? Status.UnsupportedWrite);
  }
}
class InvokeError extends SchemaViolationError {
  constructor(path, message, code) {
    super("Invoking", path, message, code ?? Status.UnsupportedAccess);
  }
}
class ValidateError extends SchemaViolationError {
  constructor(path, message, code) {
    super("Validating", path, message, code ?? Status.InvalidDataType);
  }
}
class DatatypeError extends ValidateError {
  constructor(path, type, value, code) {
    let str = `${value}`;
    if (str.length > 60) {
      str = `${str.substring(60)}\u2026`;
    }
    super(path, `Value "${str}" is not ${type}`, code);
  }
}
class ConstraintError extends ValidateError {
  constructor(schema, path, message) {
    super(path, `Constraint "${schema.constraint}": ${message}`, Status.ConstraintError);
  }
}
class IntegerRangeError extends ValidateError {
  constructor(path, message) {
    super(path, message, Status.ConstraintError);
  }
}
class UnknownEnumValueError extends ValidateError {
  constructor(path, message) {
    super(path, message, Status.ConstraintError);
  }
}
class ConformanceError extends ValidateError {
  constructor(schema, path, message, choice) {
    let prefix;
    if (choice) {
      prefix = `Conformance choice "${choice}"`;
    } else {
      prefix = `Conformance "${schema.conformance}"`;
    }
    super(path, `${prefix}: ${message}`, Status.ConstraintError);
  }
}
class EnumValueConformanceError extends ConformanceError {
}
class ExpiredReferenceError extends SchemaViolationError {
  constructor(path) {
    super("Referencing", path, "This value is no longer available because its context has exited", Status.Failure);
  }
}
class PhantomReferenceError extends SchemaViolationError {
  constructor(path) {
    super("Referencing", path, "Container was removed", Status.Failure);
  }
}
export {
  ConformanceError,
  ConstraintError,
  DatatypeError,
  EnumValueConformanceError,
  ExpiredReferenceError,
  IntegerRangeError,
  InvokeError,
  PhantomReferenceError,
  ReadError,
  SchemaImplementationError,
  SchemaViolationError,
  UnknownEnumValueError,
  ValidateError,
  WriteError
};
//# sourceMappingURL=errors.js.map
