const require_rolldown_runtime = require('../../../../../../../_virtual/rolldown_runtime.js');
const require_ValidationSchemaToMetadataTransformer$1 = require('../validation-schema/ValidationSchemaToMetadataTransformer.js');
const require_index = require('../utils/index.js');

//#region ../../node_modules/.pnpm/class-validator@0.14.1/node_modules/class-validator/cjs/metadata/MetadataStorage.js
var require_MetadataStorage = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/class-validator@0.14.1/node_modules/class-validator/cjs/metadata/MetadataStorage.js": ((exports) => {
	Object.defineProperty(exports, "__esModule", { value: true });
	const ValidationSchemaToMetadataTransformer_1 = require_ValidationSchemaToMetadataTransformer$1.require_ValidationSchemaToMetadataTransformer();
	const utils_1 = require_index.require_utils();
	/**
	* Storage all metadatas.
	*/
	var MetadataStorage = class {
		constructor() {
			this.validationMetadatas = /* @__PURE__ */ new Map();
			this.constraintMetadatas = /* @__PURE__ */ new Map();
		}
		get hasValidationMetaData() {
			return !!this.validationMetadatas.size;
		}
		/**
		* Adds a new validation metadata.
		*/
		addValidationSchema(schema) {
			new ValidationSchemaToMetadataTransformer_1.ValidationSchemaToMetadataTransformer().transform(schema).forEach((validationMetadata) => this.addValidationMetadata(validationMetadata));
		}
		/**
		* Adds a new validation metadata.
		*/
		addValidationMetadata(metadata) {
			const existingMetadata = this.validationMetadatas.get(metadata.target);
			if (existingMetadata) existingMetadata.push(metadata);
			else this.validationMetadatas.set(metadata.target, [metadata]);
		}
		/**
		* Adds a new constraint metadata.
		*/
		addConstraintMetadata(metadata) {
			const existingMetadata = this.constraintMetadatas.get(metadata.target);
			if (existingMetadata) existingMetadata.push(metadata);
			else this.constraintMetadatas.set(metadata.target, [metadata]);
		}
		/**
		* Groups metadata by their property names.
		*/
		groupByPropertyName(metadata) {
			const grouped = {};
			metadata.forEach((metadata$1) => {
				if (!grouped[metadata$1.propertyName]) grouped[metadata$1.propertyName] = [];
				grouped[metadata$1.propertyName].push(metadata$1);
			});
			return grouped;
		}
		/**
		* Gets all validation metadatas for the given object with the given groups.
		*/
		getTargetValidationMetadatas(targetConstructor, targetSchema, always, strictGroups, groups) {
			const includeMetadataBecauseOfAlwaysOption = (metadata) => {
				if (typeof metadata.always !== "undefined") return metadata.always;
				if (metadata.groups && metadata.groups.length) return false;
				return always;
			};
			const excludeMetadataBecauseOfStrictGroupsOption = (metadata) => {
				if (strictGroups) {
					if (!groups || !groups.length) {
						if (metadata.groups && metadata.groups.length) return true;
					}
				}
				return false;
			};
			const originalMetadatas = (this.validationMetadatas.get(targetConstructor) || []).filter((metadata) => {
				if (metadata.target !== targetConstructor && metadata.target !== targetSchema) return false;
				if (includeMetadataBecauseOfAlwaysOption(metadata)) return true;
				if (excludeMetadataBecauseOfStrictGroupsOption(metadata)) return false;
				if (groups && groups.length > 0) return metadata.groups && !!metadata.groups.find((group) => groups.indexOf(group) !== -1);
				return true;
			});
			const filteredForInheritedMetadatasSearch = [];
			for (const [key, value] of this.validationMetadatas.entries()) if (targetConstructor.prototype instanceof key) filteredForInheritedMetadatasSearch.push(...value);
			const uniqueInheritedMetadatas = filteredForInheritedMetadatasSearch.filter((metadata) => {
				if (typeof metadata.target === "string") return false;
				if (metadata.target === targetConstructor) return false;
				if (metadata.target instanceof Function && !(targetConstructor.prototype instanceof metadata.target)) return false;
				if (includeMetadataBecauseOfAlwaysOption(metadata)) return true;
				if (excludeMetadataBecauseOfStrictGroupsOption(metadata)) return false;
				if (groups && groups.length > 0) return metadata.groups && !!metadata.groups.find((group) => groups.indexOf(group) !== -1);
				return true;
			}).filter((inheritedMetadata) => {
				return !originalMetadatas.find((originalMetadata) => {
					return originalMetadata.propertyName === inheritedMetadata.propertyName && originalMetadata.type === inheritedMetadata.type;
				});
			});
			return originalMetadatas.concat(uniqueInheritedMetadatas);
		}
		/**
		* Gets all validator constraints for the given object.
		*/
		getTargetValidatorConstraints(target) {
			return this.constraintMetadatas.get(target) || [];
		}
	};
	exports.MetadataStorage = MetadataStorage;
	/**
	* Gets metadata storage.
	* Metadata storage follows the best practices and stores metadata in a global variable.
	*/
	function getMetadataStorage() {
		const global = (0, utils_1.getGlobal)();
		if (!global.classValidatorMetadataStorage) global.classValidatorMetadataStorage = new MetadataStorage();
		return global.classValidatorMetadataStorage;
	}
	exports.getMetadataStorage = getMetadataStorage;
}) });

//#endregion
Object.defineProperty(exports, 'default', {
  enumerable: true,
  get: function () {
    return require_MetadataStorage();
  }
});