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_DidCommOutboundMessageContext = require('../../models/DidCommOutboundMessageContext.js');
require('../../models/index.js');
const require_DidCommConnectionService = require('../connections/services/DidCommConnectionService.js');
const require_DidCommMessageSender = require('../../DidCommMessageSender.js');
require('../connections/services/index.js');
const require_DidCommBasicMessageService = require('./services/DidCommBasicMessageService.js');
require('./services/index.js');
let __credo_ts_core = require("@credo-ts/core");
__credo_ts_core = require_rolldown_runtime.__toESM(__credo_ts_core);

//#region ../didcomm/src/modules/basic-messages/DidCommBasicMessagesApi.ts
var _ref, _ref2, _ref3, _ref4;
let DidCommBasicMessagesApi = class DidCommBasicMessagesApi$1 {
	constructor(basicMessageService, messageSender, connectionService, agentContext) {
		this.basicMessageService = basicMessageService;
		this.messageSender = messageSender;
		this.connectionService = connectionService;
		this.agentContext = agentContext;
	}
	/**
	* Send a message to an active connection
	*
	* @param connectionId Connection Id
	* @param message Message contents
	* @throws {RecordNotFoundError} If connection is not found
	* @throws {MessageSendingError} If message is undeliverable
	* @returns the created record
	*/
	async sendMessage(connectionId, message, parentThreadId) {
		const connection = await this.connectionService.getById(this.agentContext, connectionId);
		const { message: basicMessage, record: basicMessageRecord } = await this.basicMessageService.createMessage(this.agentContext, message, connection, parentThreadId);
		const outboundMessageContext = new require_DidCommOutboundMessageContext.DidCommOutboundMessageContext(basicMessage, {
			agentContext: this.agentContext,
			connection,
			associatedRecord: basicMessageRecord
		});
		await this.messageSender.sendMessage(outboundMessageContext);
		return basicMessageRecord;
	}
	/**
	* Retrieve all basic messages matching a given query
	*
	* @param query The query
	* @param queryOptions The query options
	* @returns array containing all matching records
	*/
	async findAllByQuery(query, queryOptions) {
		return this.basicMessageService.findAllByQuery(this.agentContext, query, queryOptions);
	}
	/**
	* Retrieve a basic message record by id
	*
	* @param basicMessageRecordId The basic message record id
	* @throws {RecordNotFoundError} If no record is found
	* @return The basic message record
	*
	*/
	async getById(basicMessageRecordId) {
		return this.basicMessageService.getById(this.agentContext, basicMessageRecordId);
	}
	/**
	* Retrieve a basic message record by thread id
	*
	* @param threadId The thread id
	* @throws {RecordNotFoundError} If no record is found
	* @throws {RecordDuplicateError} If multiple records are found
	* @returns The connection record
	*/
	async getByThreadId(basicMessageRecordId) {
		return this.basicMessageService.getByThreadId(this.agentContext, basicMessageRecordId);
	}
	/**
	* Delete a basic message record by id
	*
	* @param connectionId the basic message record id
	* @throws {RecordNotFoundError} If no record is found
	*/
	async deleteById(basicMessageRecordId) {
		await this.basicMessageService.deleteById(this.agentContext, basicMessageRecordId);
	}
};
DidCommBasicMessagesApi = require_decorate.__decorate([(0, __credo_ts_core.injectable)(), require_decorateMetadata.__decorateMetadata("design:paramtypes", [
	typeof (_ref = typeof require_DidCommBasicMessageService.DidCommBasicMessageService !== "undefined" && require_DidCommBasicMessageService.DidCommBasicMessageService) === "function" ? _ref : Object,
	typeof (_ref2 = typeof require_DidCommMessageSender.DidCommMessageSender !== "undefined" && require_DidCommMessageSender.DidCommMessageSender) === "function" ? _ref2 : Object,
	typeof (_ref3 = typeof require_DidCommConnectionService.DidCommConnectionService !== "undefined" && require_DidCommConnectionService.DidCommConnectionService) === "function" ? _ref3 : Object,
	typeof (_ref4 = typeof __credo_ts_core.AgentContext !== "undefined" && __credo_ts_core.AgentContext) === "function" ? _ref4 : Object
])], DidCommBasicMessagesApi);

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