const require_rolldown_runtime = require('../../../../../../../_virtual/rolldown_runtime.js');
const require_decorateMetadata = require('../../../../../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.js');
const require_decorate = require('../../../../../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.js');
const require_decorateParam = require('../../../../../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateParam.js');
const require_DidCommFeatureRegistry = require('../../../../DidCommFeatureRegistry.js');
require('../../../../DidCommMessageHandlerRegistry.js');
const require_DidCommDiscoverFeaturesEvents = require('../../DidCommDiscoverFeaturesEvents.js');
const require_DidCommDiscoverFeaturesModuleConfig = require('../../DidCommDiscoverFeaturesModuleConfig.js');
const require_DidCommDiscoverFeaturesService = require('../../services/DidCommDiscoverFeaturesService.js');
const require_DidCommFeaturesDisclosuresMessage = require('./messages/DidCommFeaturesDisclosuresMessage.js');
const require_DidCommFeaturesQueriesMessage = require('./messages/DidCommFeaturesQueriesMessage.js');
require('./messages/index.js');
const require_DidCommFeaturesDisclosuresMessageHandler = require('./handlers/DidCommFeaturesDisclosuresMessageHandler.js');
const require_DidCommFeaturesQueriesMessageHandler = require('./handlers/DidCommFeaturesQueriesMessageHandler.js');
require('./handlers/index.js');
let __credo_ts_core = require("@credo-ts/core");
__credo_ts_core = require_rolldown_runtime.__toESM(__credo_ts_core);

//#region ../didcomm/src/modules/discover-features/protocol/v2/DidCommDiscoverFeaturesV2Service.ts
var _ref, _ref2, _ref3;
let DidCommDiscoverFeaturesV2Service = class DidCommDiscoverFeaturesV2Service$1 extends require_DidCommDiscoverFeaturesService.DidCommDiscoverFeaturesService {
	constructor(featureRegistry, eventEmitter, logger, discoverFeaturesModuleConfig) {
		super(featureRegistry, eventEmitter, logger, discoverFeaturesModuleConfig);
		this.version = "v2";
	}
	register(messageHandlerRegistry) {
		messageHandlerRegistry.registerMessageHandler(new require_DidCommFeaturesDisclosuresMessageHandler.DidCommFeaturesDisclosuresMessageHandler(this));
		messageHandlerRegistry.registerMessageHandler(new require_DidCommFeaturesQueriesMessageHandler.DidCommFeaturesQueriesMessageHandler(this));
	}
	async createQuery(options) {
		return { message: new require_DidCommFeaturesQueriesMessage.DidCommFeaturesQueriesMessage({ queries: options.queries }) };
	}
	async processQuery(messageContext) {
		const { queries, threadId } = messageContext.message;
		const connection = messageContext.assertReadyConnection();
		this.eventEmitter.emit(messageContext.agentContext, {
			type: require_DidCommDiscoverFeaturesEvents.DidCommDiscoverFeaturesEventTypes.QueryReceived,
			payload: {
				message: messageContext.message,
				connection,
				queries,
				protocolVersion: this.version,
				threadId
			}
		});
		if (this.discoverFeaturesModuleConfig.autoAcceptQueries) return await this.createDisclosure({
			threadId,
			disclosureQueries: queries
		});
	}
	async createDisclosure(options) {
		const matches = this.featureRegistry.query(...options.disclosureQueries);
		return { message: new require_DidCommFeaturesDisclosuresMessage.DidCommFeaturesDisclosuresMessage({
			threadId: options.threadId,
			features: matches
		}) };
	}
	async processDisclosure(messageContext) {
		const { disclosures, threadId } = messageContext.message;
		const connection = messageContext.assertReadyConnection();
		this.eventEmitter.emit(messageContext.agentContext, {
			type: require_DidCommDiscoverFeaturesEvents.DidCommDiscoverFeaturesEventTypes.DisclosureReceived,
			payload: {
				message: messageContext.message,
				connection,
				disclosures,
				protocolVersion: this.version,
				threadId
			}
		});
	}
};
DidCommDiscoverFeaturesV2Service = require_decorate.__decorate([
	(0, __credo_ts_core.injectable)(),
	require_decorateParam.__decorateParam(2, (0, __credo_ts_core.inject)(__credo_ts_core.InjectionSymbols.Logger)),
	require_decorateMetadata.__decorateMetadata("design:paramtypes", [
		typeof (_ref = typeof require_DidCommFeatureRegistry.DidCommFeatureRegistry !== "undefined" && require_DidCommFeatureRegistry.DidCommFeatureRegistry) === "function" ? _ref : Object,
		typeof (_ref2 = typeof __credo_ts_core.EventEmitter !== "undefined" && __credo_ts_core.EventEmitter) === "function" ? _ref2 : Object,
		Object,
		typeof (_ref3 = typeof require_DidCommDiscoverFeaturesModuleConfig.DidCommDiscoverFeaturesModuleConfig !== "undefined" && require_DidCommDiscoverFeaturesModuleConfig.DidCommDiscoverFeaturesModuleConfig) === "function" ? _ref3 : Object
	])
], DidCommDiscoverFeaturesV2Service);

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