const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.js');
const require_messageType = require('../util/messageType.js');
let __credo_ts_core = require("@credo-ts/core");
__credo_ts_core = require_rolldown_runtime.__toESM(__credo_ts_core);

//#region ../didcomm/src/repository/DidCommMessageRecord.ts
var DidCommMessageRecord = class DidCommMessageRecord extends __credo_ts_core.BaseRecord {
	constructor(props) {
		super();
		this.type = DidCommMessageRecord.type;
		if (props) {
			this.id = props.id ?? __credo_ts_core.utils.uuid();
			this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
			this.associatedRecordId = props.associatedRecordId;
			this.role = props.role;
			this.message = props.message;
		}
	}
	getTags() {
		const messageId = this.message["@id"];
		const messageType = this.message["@type"];
		const { protocolName, protocolMajorVersion, protocolMinorVersion, messageName } = require_messageType.parseMessageType(messageType);
		const thread = this.message["~thread"];
		let threadId = messageId;
		if ((0, __credo_ts_core.isJsonObject)(thread) && typeof thread.thid === "string") threadId = thread.thid;
		return {
			...this._tags,
			role: this.role,
			associatedRecordId: this.associatedRecordId,
			threadId,
			protocolName,
			messageName,
			protocolMajorVersion: protocolMajorVersion.toString(),
			protocolMinorVersion: protocolMinorVersion.toString(),
			messageType,
			messageId
		};
	}
	getMessageInstance(messageClass) {
		if (!require_messageType.canHandleMessageType(messageClass, require_messageType.parseMessageType(this.message["@type"]))) throw new __credo_ts_core.CredoError("Provided message class type does not match type of stored message");
		return __credo_ts_core.JsonTransformer.fromJSON(this.message, messageClass);
	}
};
DidCommMessageRecord.type = "DidCommMessageRecord";

//#endregion
exports.DidCommMessageRecord = DidCommMessageRecord;