const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
const require_core = require('./core.cjs');
const require_util = require('./util.cjs');
const require_errors = require('./errors.cjs');

//#region ../../node_modules/zod/v4/core/parse.js
const _parse = (_Err) => (schema, value, _ctx, _params) => {
	const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
	const result = schema._zod.run({
		value,
		issues: []
	}, ctx);
	if (result instanceof Promise) throw new require_core.$ZodAsyncError();
	if (result.issues.length) {
		const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => require_util.finalizeIssue(iss, ctx, require_core.config())));
		require_util.captureStackTrace(e, _params?.callee);
		throw e;
	}
	return result.value;
};
const parse = /* @__PURE__ */ _parse(require_errors.$ZodRealError);
const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
	const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
	let result = schema._zod.run({
		value,
		issues: []
	}, ctx);
	if (result instanceof Promise) result = await result;
	if (result.issues.length) {
		const e = new (params?.Err ?? _Err)(result.issues.map((iss) => require_util.finalizeIssue(iss, ctx, require_core.config())));
		require_util.captureStackTrace(e, params?.callee);
		throw e;
	}
	return result.value;
};
const parseAsync = /* @__PURE__ */ _parseAsync(require_errors.$ZodRealError);
const _safeParse = (_Err) => (schema, value, _ctx) => {
	const ctx = _ctx ? {
		..._ctx,
		async: false
	} : { async: false };
	const result = schema._zod.run({
		value,
		issues: []
	}, ctx);
	if (result instanceof Promise) throw new require_core.$ZodAsyncError();
	return result.issues.length ? {
		success: false,
		error: new (_Err ?? require_errors.$ZodError)(result.issues.map((iss) => require_util.finalizeIssue(iss, ctx, require_core.config())))
	} : {
		success: true,
		data: result.value
	};
};
const safeParse = /* @__PURE__ */ _safeParse(require_errors.$ZodRealError);
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
	const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
	let result = schema._zod.run({
		value,
		issues: []
	}, ctx);
	if (result instanceof Promise) result = await result;
	return result.issues.length ? {
		success: false,
		error: new _Err(result.issues.map((iss) => require_util.finalizeIssue(iss, ctx, require_core.config())))
	} : {
		success: true,
		data: result.value
	};
};
const safeParseAsync = /* @__PURE__ */ _safeParseAsync(require_errors.$ZodRealError);
const _encode = (_Err) => (schema, value, _ctx) => {
	const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
	return _parse(_Err)(schema, value, ctx);
};
const encode = /* @__PURE__ */ _encode(require_errors.$ZodRealError);
const _decode = (_Err) => (schema, value, _ctx) => {
	return _parse(_Err)(schema, value, _ctx);
};
const decode = /* @__PURE__ */ _decode(require_errors.$ZodRealError);
const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
	const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
	return _parseAsync(_Err)(schema, value, ctx);
};
const encodeAsync = /* @__PURE__ */ _encodeAsync(require_errors.$ZodRealError);
const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
	return _parseAsync(_Err)(schema, value, _ctx);
};
const decodeAsync = /* @__PURE__ */ _decodeAsync(require_errors.$ZodRealError);
const _safeEncode = (_Err) => (schema, value, _ctx) => {
	const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
	return _safeParse(_Err)(schema, value, ctx);
};
const safeEncode = /* @__PURE__ */ _safeEncode(require_errors.$ZodRealError);
const _safeDecode = (_Err) => (schema, value, _ctx) => {
	return _safeParse(_Err)(schema, value, _ctx);
};
const safeDecode = /* @__PURE__ */ _safeDecode(require_errors.$ZodRealError);
const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
	const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
	return _safeParseAsync(_Err)(schema, value, ctx);
};
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(require_errors.$ZodRealError);
const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
	return _safeParseAsync(_Err)(schema, value, _ctx);
};
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(require_errors.$ZodRealError);

//#endregion
exports._decode = _decode;
exports._decodeAsync = _decodeAsync;
exports._encode = _encode;
exports._encodeAsync = _encodeAsync;
exports._parse = _parse;
exports._parseAsync = _parseAsync;
exports._safeDecode = _safeDecode;
exports._safeDecodeAsync = _safeDecodeAsync;
exports._safeEncode = _safeEncode;
exports._safeEncodeAsync = _safeEncodeAsync;
exports._safeParse = _safeParse;
exports._safeParseAsync = _safeParseAsync;
exports.safeParse = safeParse;
exports.safeParseAsync = safeParseAsync;
//# sourceMappingURL=parse.cjs.map