

const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
const require_array = require('./array.js');
let class_validator = require("class-validator");

//#region src/utils/validators.ts
/**
* Checks if the value is a string or the specified instance
*/
function IsStringOrInstance(targetType, validationOptions) {
	return (0, class_validator.ValidateBy)({
		name: "IsStringOrInstance",
		constraints: [targetType],
		validator: {
			validate: (value, args) => (0, class_validator.isString)(value) || (0, class_validator.isInstance)(value, args?.constraints[0]),
			defaultMessage: (0, class_validator.buildMessage)((eachPrefix, args) => {
				if (args?.constraints[0]) return `${eachPrefix}$property must be of type string or instance of ${args.constraints[0].name}`;
				return `${eachPrefix}IsStringOrInstance decorator expects an object as value, but got falsy value.`;
			}, validationOptions)
		}
	}, validationOptions);
}
function IsInstanceOrArrayOfInstances(validationOptions) {
	const classTypes = require_array.asArray(validationOptions.classType);
	const allowEmptyArray = validationOptions.allowEmptyArray ?? false;
	return (0, class_validator.ValidateBy)({
		name: "isInstanceOrArrayOfInstances",
		validator: {
			validate: (values) => {
				if (!values) return false;
				if (Array.isArray(values) && values.length === 0) return allowEmptyArray;
				return require_array.asArray(values).every((value) => classTypes.some((classType) => (0, class_validator.isInstance)(value, classType)));
			},
			defaultMessage: (0, class_validator.buildMessage)((eachPrefix) => `${eachPrefix}$property value must be an instance of, or an array of instances containing ${classTypes.map((c) => c.name).join(", ")}`, validationOptions)
		}
	}, validationOptions);
}
function IsStringOrInstanceOrArrayOfInstances(validationOptions) {
	const classTypes = require_array.asArray(validationOptions.classType);
	const allowEmptyArray = validationOptions.allowEmptyArray ?? false;
	return (0, class_validator.ValidateBy)({
		name: "IsStringOrInstanceOrArrayOfInstances",
		validator: {
			validate: (values) => {
				if ((0, class_validator.isString)(values)) return true;
				if (!values) return false;
				if (Array.isArray(values) && values.length === 0) return allowEmptyArray;
				return require_array.asArray(values).every((value) => classTypes.some((classType) => (0, class_validator.isInstance)(value, classType)));
			},
			defaultMessage: (0, class_validator.buildMessage)((eachPrefix) => `${eachPrefix}$property value must be a string, an instance of, or an array of instances containing ${classTypes.map((c) => c.name).join(", ")}`, validationOptions)
		}
	}, validationOptions);
}
const UriValidator = /\w+:(\/?\/?)[^\s]+/;
function isUri(value) {
	return UriValidator.test(value);
}
function IsUri(validationOptions) {
	return (0, class_validator.ValidateBy)({
		name: "isUri",
		validator: {
			validate: (value) => isUri(value),
			defaultMessage: (0, class_validator.buildMessage)((eachPrefix) => `${eachPrefix}$property must be an URI (that matches regex: ${UriValidator.source})`, validationOptions)
		}
	}, validationOptions);
}
function IsNever(validationOptions) {
	return (0, class_validator.ValidateBy)({
		name: "IsNever",
		validator: {
			validate: (values) => typeof values === "undefined",
			defaultMessage: (0, class_validator.buildMessage)((eachPrefix) => `${eachPrefix}$property is forbidden.`, validationOptions)
		}
	}, validationOptions);
}

//#endregion
exports.IsInstanceOrArrayOfInstances = IsInstanceOrArrayOfInstances;
exports.IsNever = IsNever;
exports.IsStringOrInstance = IsStringOrInstance;
exports.IsStringOrInstanceOrArrayOfInstances = IsStringOrInstanceOrArrayOfInstances;
exports.IsUri = IsUri;
exports.UriValidator = UriValidator;
exports.isUri = isUri;