"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 errors_exports = {};
__export(errors_exports, {
  ConformanceError: () => ConformanceError,
  ConstraintError: () => ConstraintError,
  DatatypeError: () => DatatypeError,
  EnumValueConformanceError: () => EnumValueConformanceError,
  ExpiredReferenceError: () => ExpiredReferenceError,
  IntegerRangeError: () => IntegerRangeError,
  InvokeError: () => InvokeError,
  PhantomReferenceError: () => PhantomReferenceError,
  ReadError: () => ReadError,
  SchemaImplementationError: () => import_model2.SchemaImplementationError,
  SchemaViolationError: () => SchemaViolationError,
  UnknownEnumValueError: () => UnknownEnumValueError,
  ValidateError: () => ValidateError,
  WriteError: () => WriteError
});
module.exports = __toCommonJS(errors_exports);
var import_types = require("#types");
var import_model2 = require("#model");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class SchemaViolationError extends import_types.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 ?? import_types.Status.UnsupportedRead);
  }
}
class WriteError extends SchemaViolationError {
  constructor(path, message, code) {
    super("Writing", path, message, code ?? import_types.Status.UnsupportedWrite);
  }
}
class InvokeError extends SchemaViolationError {
  constructor(path, message, code) {
    super("Invoking", path, message, code ?? import_types.Status.UnsupportedAccess);
  }
}
class ValidateError extends SchemaViolationError {
  constructor(path, message, code) {
    super("Validating", path, message, code ?? import_types.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}`, import_types.Status.ConstraintError);
  }
}
class IntegerRangeError extends ValidateError {
  constructor(path, message) {
    super(path, message, import_types.Status.ConstraintError);
  }
}
class UnknownEnumValueError extends ValidateError {
  constructor(path, message) {
    super(path, message, import_types.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}`, import_types.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", import_types.Status.Failure);
  }
}
class PhantomReferenceError extends SchemaViolationError {
  constructor(path) {
    super("Referencing", path, "Container was removed", import_types.Status.Failure);
  }
}
//# sourceMappingURL=errors.js.map
