import { __decorateMetadata } from "../../../../../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.mjs";
import { __decorate } from "../../../../../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.mjs";
import { __decorateParam } from "../../../../../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateParam.mjs";
import { DidCommFeatureRegistry } from "../../../../DidCommFeatureRegistry.mjs";
import "../../../../DidCommMessageHandlerRegistry.mjs";
import { DidCommDiscoverFeaturesEventTypes } from "../../DidCommDiscoverFeaturesEvents.mjs";
import { DidCommDiscoverFeaturesModuleConfig } from "../../DidCommDiscoverFeaturesModuleConfig.mjs";
import { DidCommDiscoverFeaturesService } from "../../services/DidCommDiscoverFeaturesService.mjs";
import { DidCommFeaturesDisclosuresMessage } from "./messages/DidCommFeaturesDisclosuresMessage.mjs";
import { DidCommFeaturesQueriesMessage } from "./messages/DidCommFeaturesQueriesMessage.mjs";
import "./messages/index.mjs";
import { DidCommFeaturesDisclosuresMessageHandler } from "./handlers/DidCommFeaturesDisclosuresMessageHandler.mjs";
import { DidCommFeaturesQueriesMessageHandler } from "./handlers/DidCommFeaturesQueriesMessageHandler.mjs";
import "./handlers/index.mjs";
import { EventEmitter, InjectionSymbols, inject, injectable } from "@credo-ts/core";

//#region ../didcomm/src/modules/discover-features/protocol/v2/DidCommDiscoverFeaturesV2Service.ts
var _ref, _ref2, _ref3;
let DidCommDiscoverFeaturesV2Service = class DidCommDiscoverFeaturesV2Service$1 extends DidCommDiscoverFeaturesService {
	constructor(featureRegistry, eventEmitter, logger, discoverFeaturesModuleConfig) {
		super(featureRegistry, eventEmitter, logger, discoverFeaturesModuleConfig);
		this.version = "v2";
	}
	register(messageHandlerRegistry) {
		messageHandlerRegistry.registerMessageHandler(new DidCommFeaturesDisclosuresMessageHandler(this));
		messageHandlerRegistry.registerMessageHandler(new DidCommFeaturesQueriesMessageHandler(this));
	}
	async createQuery(options) {
		return { message: new DidCommFeaturesQueriesMessage({ queries: options.queries }) };
	}
	async processQuery(messageContext) {
		const { queries, threadId } = messageContext.message;
		const connection = messageContext.assertReadyConnection();
		this.eventEmitter.emit(messageContext.agentContext, {
			type: 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 DidCommFeaturesDisclosuresMessage({
			threadId: options.threadId,
			features: matches
		}) };
	}
	async processDisclosure(messageContext) {
		const { disclosures, threadId } = messageContext.message;
		const connection = messageContext.assertReadyConnection();
		this.eventEmitter.emit(messageContext.agentContext, {
			type: DidCommDiscoverFeaturesEventTypes.DisclosureReceived,
			payload: {
				message: messageContext.message,
				connection,
				disclosures,
				protocolVersion: this.version,
				threadId
			}
		});
	}
};
DidCommDiscoverFeaturesV2Service = __decorate([
	injectable(),
	__decorateParam(2, inject(InjectionSymbols.Logger)),
	__decorateMetadata("design:paramtypes", [
		typeof (_ref = typeof DidCommFeatureRegistry !== "undefined" && DidCommFeatureRegistry) === "function" ? _ref : Object,
		typeof (_ref2 = typeof EventEmitter !== "undefined" && EventEmitter) === "function" ? _ref2 : Object,
		Object,
		typeof (_ref3 = typeof DidCommDiscoverFeaturesModuleConfig !== "undefined" && DidCommDiscoverFeaturesModuleConfig) === "function" ? _ref3 : Object
	])
], DidCommDiscoverFeaturesV2Service);

//#endregion
export { DidCommDiscoverFeaturesV2Service };
//# sourceMappingURL=DidCommDiscoverFeaturesV2Service.mjs.map