import { __exports as l } from "../../../../../../../_virtual/errors.js";
import { __require as O } from "./codegen/index.js";
import { __require as R } from "./util.js";
import { __require as C } from "./names.js";
var w;
function U() {
  return w ? l : (w = 1, function(n) {
    Object.defineProperty(n, "__esModule", { value: !0 }), n.extendErrors = n.resetErrorsCount = n.reportExtraError = n.reportError = n.keyword$DataError = n.keywordError = void 0;
    const e = O(), E = R(), i = C();
    n.keywordError = {
      message: ({ keyword: r }) => (0, e.str)`must pass "${r}" keyword validation`
    }, n.keyword$DataError = {
      message: ({ keyword: r, schemaType: t }) => t ? (0, e.str)`"${r}" keyword must be ${t} ($data)` : (0, e.str)`"${r}" keyword is invalid ($data)`
    };
    function y(r, t = n.keywordError, o, a) {
      const { it: s } = r, { gen: u, compositeRule: c, allErrors: d } = s, m = _(r, t, o);
      a ?? (c || d) ? h(u, m) : $(s, (0, e._)`[${m}]`);
    }
    n.reportError = y;
    function v(r, t = n.keywordError, o) {
      const { it: a } = r, { gen: s, compositeRule: u, allErrors: c } = a, d = _(r, t, o);
      h(s, d), u || c || $(a, i.default.vErrors);
    }
    n.reportExtraError = v;
    function P(r, t) {
      r.assign(i.default.errors, t), r.if((0, e._)`${i.default.vErrors} !== null`, () => r.if(t, () => r.assign((0, e._)`${i.default.vErrors}.length`, t), () => r.assign(i.default.vErrors, null)));
    }
    n.resetErrorsCount = P;
    function N({ gen: r, keyword: t, schemaValue: o, data: a, errsCount: s, it: u }) {
      if (s === void 0)
        throw new Error("ajv implementation error");
      const c = r.name("err");
      r.forRange("i", s, i.default.errors, (d) => {
        r.const(c, (0, e._)`${i.default.vErrors}[${d}]`), r.if((0, e._)`${c}.instancePath === undefined`, () => r.assign((0, e._)`${c}.instancePath`, (0, e.strConcat)(i.default.instancePath, u.errorPath))), r.assign((0, e._)`${c}.schemaPath`, (0, e.str)`${u.errSchemaPath}/${t}`), u.opts.verbose && (r.assign((0, e._)`${c}.schema`, o), r.assign((0, e._)`${c}.data`, a));
      });
    }
    n.extendErrors = N;
    function h(r, t) {
      const o = r.const("err", t);
      r.if((0, e._)`${i.default.vErrors} === null`, () => r.assign(i.default.vErrors, (0, e._)`[${o}]`), (0, e._)`${i.default.vErrors}.push(${o})`), r.code((0, e._)`${i.default.errors}++`);
    }
    function $(r, t) {
      const { gen: o, validateName: a, schemaEnv: s } = r;
      s.$async ? o.throw((0, e._)`new ${r.ValidationError}(${t})`) : (o.assign((0, e._)`${a}.errors`, t), o.return(!1));
    }
    const f = {
      keyword: new e.Name("keyword"),
      schemaPath: new e.Name("schemaPath"),
      // also used in JTD errors
      params: new e.Name("params"),
      propertyName: new e.Name("propertyName"),
      message: new e.Name("message"),
      schema: new e.Name("schema"),
      parentSchema: new e.Name("parentSchema")
    };
    function _(r, t, o) {
      const { createErrors: a } = r.it;
      return a === !1 ? (0, e._)`{}` : k(r, t, o);
    }
    function k(r, t, o = {}) {
      const { gen: a, it: s } = r, u = [
        b(s, o),
        g(r, o)
      ];
      return q(r, t, u), a.object(...u);
    }
    function b({ errorPath: r }, { instancePath: t }) {
      const o = t ? (0, e.str)`${r}${(0, E.getErrorPath)(t, E.Type.Str)}` : r;
      return [i.default.instancePath, (0, e.strConcat)(i.default.instancePath, o)];
    }
    function g({ keyword: r, it: { errSchemaPath: t } }, { schemaPath: o, parentSchema: a }) {
      let s = a ? t : (0, e.str)`${t}/${r}`;
      return o && (s = (0, e.str)`${s}${(0, E.getErrorPath)(o, E.Type.Str)}`), [f.schemaPath, s];
    }
    function q(r, { params: t, message: o }, a) {
      const { keyword: s, data: u, schemaValue: c, it: d } = r, { opts: m, propertyName: p, topSchemaRef: j, schemaPath: S } = d;
      a.push([f.keyword, s], [f.params, typeof t == "function" ? t(r) : t || (0, e._)`{}`]), m.messages && a.push([f.message, typeof o == "function" ? o(r) : o]), m.verbose && a.push([f.schema, c], [f.parentSchema, (0, e._)`${j}${S}`], [i.default.data, u]), p && a.push([f.propertyName, p]);
    }
  }(l), l);
}
export {
  U as __require
};
//# sourceMappingURL=errors.js.map
