const require_rolldown_runtime = require('../../../../../../_virtual/rolldown_runtime.js');
const require_index = require('../../../../../../node_modules/.pnpm/class-transformer@0.5.1/node_modules/class-transformer/cjs/index.js');
const require_index$1 = require('../../../../../../node_modules/.pnpm/class-validator@0.14.1/node_modules/class-validator/cjs/index.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_messageType = require('../../../util/messageType.js');
const require_DidCommMessage = require('../../../DidCommMessage.js');
const require_index$2 = require('../../../../../../node_modules/.pnpm/query-string@7.1.3/node_modules/query-string/index.js');
let __credo_ts_core = require("@credo-ts/core");
__credo_ts_core = require_rolldown_runtime.__toESM(__credo_ts_core);

//#region ../didcomm/src/modules/connections/messages/DidCommConnectionInvitationMessage.ts
var import_cjs = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_index.require_cjs());
var import_cjs$1 = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_index$1.require_cjs());
var import_query_string = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_index$2.require_query_string());
/**
* Message to invite another agent to create a connection
*
* @see https://github.com/hyperledger/aries-rfcs/blob/master/features/0160-connection-protocol/README.md#0-invitation-to-connect
*/
var DidCommConnectionInvitationMessage = class DidCommConnectionInvitationMessage extends require_DidCommMessage.DidCommMessage {
	/**
	* Create new DidCommConnectionInvitationMessage instance.
	* @param options
	*/
	constructor(options) {
		super();
		this.allowDidSovPrefix = true;
		this.type = DidCommConnectionInvitationMessage.type.messageTypeUri;
		if (options) {
			this.id = options.id || this.generateId();
			this.label = options.label;
			this.imageUrl = options.imageUrl;
			this.appendedAttachments = options.appendedAttachments;
			if (isDidInvitation(options)) this.did = options.did;
			else {
				this.recipientKeys = options.recipientKeys;
				this.serviceEndpoint = options.serviceEndpoint;
				this.routingKeys = options.routingKeys;
			}
			if (options.did && (options.recipientKeys || options.routingKeys || options.serviceEndpoint)) throw new __credo_ts_core.CredoError("either the did or the recipientKeys/serviceEndpoint/routingKeys must be set, but not both");
		}
	}
	/**
	* Create an invitation url from this instance
	*
	* @param domain domain name to use for invitation url
	* @returns invitation url with base64 encoded invitation
	*/
	toUrl({ domain, useDidSovPrefixWhereAllowed = false }) {
		const invitationJson = this.toJSON({ useDidSovPrefixWhereAllowed });
		return `${domain}?c_i=${__credo_ts_core.JsonEncoder.toBase64URL(invitationJson)}`;
	}
	/**
	* Create a `DidCommConnectionInvitationMessage` instance from the `c_i` or `d_m` parameter of an URL
	*
	* @param invitationUrl invitation url containing c_i or d_m parameter
	*
	* @throws Error when the url can not be decoded to JSON, or decoded message is not a valid 'DidCommConnectionInvitationMessage'
	*/
	static fromUrl(invitationUrl) {
		const parsedUrl = (0, import_query_string.parseUrl)(invitationUrl).query;
		const encodedInvitation = parsedUrl.c_i ?? parsedUrl.d_m;
		if (typeof encodedInvitation === "string") {
			const invitationJson = __credo_ts_core.JsonEncoder.fromBase64(encodedInvitation);
			return __credo_ts_core.JsonTransformer.fromJSON(invitationJson, DidCommConnectionInvitationMessage);
		}
		throw new __credo_ts_core.CredoError("InvitationUrl is invalid. Needs to be encoded with either c_i, d_m, or oob");
	}
};
DidCommConnectionInvitationMessage.type = require_messageType.parseMessageType("https://didcomm.org/connections/1.0/invitation");
require_decorate.__decorate([
	require_messageType.IsValidMessageType(DidCommConnectionInvitationMessage.type),
	(0, import_cjs.Transform)(({ value }) => require_messageType.replaceLegacyDidSovPrefix(value), { toClassOnly: true }),
	require_decorateMetadata.__decorateMetadata("design:type", Object)
], DidCommConnectionInvitationMessage.prototype, "type", void 0);
require_decorate.__decorate([(0, import_cjs$1.IsString)(), require_decorateMetadata.__decorateMetadata("design:type", String)], DidCommConnectionInvitationMessage.prototype, "label", void 0);
require_decorate.__decorate([
	(0, import_cjs$1.IsString)(),
	(0, import_cjs$1.ValidateIf)((o) => o.recipientKeys === void 0),
	require_decorateMetadata.__decorateMetadata("design:type", String)
], DidCommConnectionInvitationMessage.prototype, "did", void 0);
require_decorate.__decorate([
	(0, import_cjs$1.IsString)({ each: true }),
	(0, import_cjs$1.IsArray)(),
	(0, import_cjs$1.ValidateIf)((o) => o.did === void 0),
	(0, import_cjs$1.ArrayNotEmpty)(),
	require_decorateMetadata.__decorateMetadata("design:type", Array)
], DidCommConnectionInvitationMessage.prototype, "recipientKeys", void 0);
require_decorate.__decorate([
	(0, import_cjs$1.IsString)(),
	(0, import_cjs$1.ValidateIf)((o) => o.did === void 0),
	require_decorateMetadata.__decorateMetadata("design:type", String)
], DidCommConnectionInvitationMessage.prototype, "serviceEndpoint", void 0);
require_decorate.__decorate([
	(0, import_cjs$1.IsString)({ each: true }),
	(0, import_cjs$1.ValidateIf)((o) => o.did === void 0),
	(0, import_cjs$1.IsOptional)(),
	require_decorateMetadata.__decorateMetadata("design:type", Array)
], DidCommConnectionInvitationMessage.prototype, "routingKeys", void 0);
require_decorate.__decorate([
	(0, import_cjs$1.IsOptional)(),
	(0, import_cjs$1.IsUrl)(),
	require_decorateMetadata.__decorateMetadata("design:type", String)
], DidCommConnectionInvitationMessage.prototype, "imageUrl", void 0);
/**
* Check whether an invitation is a `DIDInvitationData` object
*
* @param invitation invitation object
*/
function isDidInvitation(invitation) {
	return invitation.did !== void 0;
}

//#endregion
exports.DidCommConnectionInvitationMessage = DidCommConnectionInvitationMessage;