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 { DidCommOutboundMessageContext } from "../../models/DidCommOutboundMessageContext.mjs";
import "../../models/index.mjs";
import { DidCommConnectionService } from "../connections/services/DidCommConnectionService.mjs";
import { DidCommMessageSender } from "../../DidCommMessageSender.mjs";
import "../connections/services/index.mjs";
import { DidCommBasicMessageService } from "./services/DidCommBasicMessageService.mjs";
import "./services/index.mjs";
import { AgentContext, injectable } from "@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 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 = __decorate([injectable(), __decorateMetadata("design:paramtypes", [
	typeof (_ref = typeof DidCommBasicMessageService !== "undefined" && DidCommBasicMessageService) === "function" ? _ref : Object,
	typeof (_ref2 = typeof DidCommMessageSender !== "undefined" && DidCommMessageSender) === "function" ? _ref2 : Object,
	typeof (_ref3 = typeof DidCommConnectionService !== "undefined" && DidCommConnectionService) === "function" ? _ref3 : Object,
	typeof (_ref4 = typeof AgentContext !== "undefined" && AgentContext) === "function" ? _ref4 : Object
])], DidCommBasicMessagesApi);

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