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_DidCommAttachment = require('../../../decorators/attachment/DidCommAttachment.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');
const require_OutOfBandDidCommService = require('../domain/OutOfBandDidCommService.js');
const require_helpers = require('../helpers.js');
let __credo_ts_core = require("@credo-ts/core");
__credo_ts_core = require_rolldown_runtime.__toESM(__credo_ts_core);

//#region ../didcomm/src/modules/oob/messages/DidCommOutOfBandInvitation.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());
var _ref, _ref2;
/**
* The original invitation an out of band invitation was derived from.
*/
let DidCommInvitationType = /* @__PURE__ */ function(DidCommInvitationType$1) {
	DidCommInvitationType$1["OutOfBand"] = "out-of-band/1.x";
	DidCommInvitationType$1["Connection"] = "connections/1.x";
	DidCommInvitationType$1["Connectionless"] = "connectionless";
	return DidCommInvitationType$1;
}({});
var DidCommOutOfBandInvitation = class DidCommOutOfBandInvitation extends require_DidCommMessage.DidCommMessage {
	constructor(options) {
		super();
		this.type = DidCommOutOfBandInvitation.type.messageTypeUri;
		if (options) {
			this.id = options.id ?? this.generateId();
			this.label = options.label;
			this.goalCode = options.goalCode;
			this.goal = options.goal;
			this.accept = options.accept;
			this.handshakeProtocols = options.handshakeProtocols;
			this.services = options.services;
			this.imageUrl = options.imageUrl;
			this.appendedAttachments = options.appendedAttachments;
		}
	}
	addRequest(message) {
		if (!this.requests) this.requests = [];
		const requestAttachment = new require_DidCommAttachment.DidCommAttachment({
			id: this.generateId(),
			mimeType: "application/json",
			data: new require_DidCommAttachment.DidCommAttachmentData({ base64: __credo_ts_core.JsonEncoder.toBase64(message.toJSON()) })
		});
		this.requests.push(requestAttachment);
	}
	getRequests() {
		return this.requests?.map((request) => request.getDataAsJson());
	}
	toUrl({ domain }) {
		const invitationJson = this.toJSON();
		return `${domain}?oob=${__credo_ts_core.JsonEncoder.toBase64URL(invitationJson)}`;
	}
	static fromUrl(invitationUrl) {
		const encodedInvitation = (0, import_query_string.parseUrl)(invitationUrl).query.oob;
		if (typeof encodedInvitation === "string") {
			const invitationJson = __credo_ts_core.JsonEncoder.fromBase64(encodedInvitation);
			return DidCommOutOfBandInvitation.fromJson(invitationJson);
		}
		throw new __credo_ts_core.CredoError("InvitationUrl is invalid. It needs to contain one, and only one, of the following parameters; `oob`");
	}
	static fromJson(json) {
		return __credo_ts_core.JsonTransformer.fromJSON(json, DidCommOutOfBandInvitation);
	}
	get invitationDids() {
		return this.getServices().map((didOrService) => {
			if (typeof didOrService === "string") return didOrService;
			return require_helpers.outOfBandServiceToNumAlgo2Did(didOrService);
		});
	}
	getServices() {
		return this.services.map((service) => {
			if (service instanceof String) return service.toString();
			return service;
		});
	}
	getDidServices() {
		return this.getServices().filter((service) => typeof service === "string");
	}
	getInlineServices() {
		return this.getServices().filter((service) => typeof service !== "string");
	}
};
DidCommOutOfBandInvitation.type = require_messageType.parseMessageType("https://didcomm.org/out-of-band/1.1/invitation");
require_decorate.__decorate([(0, import_cjs.Exclude)(), require_decorateMetadata.__decorateMetadata("design:type", typeof (_ref = typeof DidCommInvitationType !== "undefined" && DidCommInvitationType) === "function" ? _ref : Object)], DidCommOutOfBandInvitation.prototype, "invitationType", void 0);
require_decorate.__decorate([
	(0, import_cjs.Transform)(({ value }) => require_messageType.replaceLegacyDidSovPrefix(value), { toClassOnly: true }),
	require_messageType.IsValidMessageType(DidCommOutOfBandInvitation.type),
	require_decorateMetadata.__decorateMetadata("design:type", Object)
], DidCommOutOfBandInvitation.prototype, "type", void 0);
require_decorate.__decorate([(0, import_cjs.Expose)({ name: "goal_code" }), require_decorateMetadata.__decorateMetadata("design:type", String)], DidCommOutOfBandInvitation.prototype, "goalCode", void 0);
require_decorate.__decorate([
	(0, import_cjs.Transform)(({ value }) => value?.map(require_messageType.replaceLegacyDidSovPrefix), { toClassOnly: true }),
	(0, import_cjs.Expose)({ name: "handshake_protocols" }),
	require_decorateMetadata.__decorateMetadata("design:type", Array)
], DidCommOutOfBandInvitation.prototype, "handshakeProtocols", void 0);
require_decorate.__decorate([
	(0, import_cjs.Expose)({ name: "requests~attach" }),
	(0, import_cjs.Type)(() => require_DidCommAttachment.DidCommAttachment),
	(0, import_cjs$1.IsArray)(),
	(0, import_cjs$1.ValidateNested)({ each: true }),
	(0, import_cjs$1.IsInstance)(require_DidCommAttachment.DidCommAttachment, { each: true }),
	(0, import_cjs$1.IsOptional)(),
	require_decorateMetadata.__decorateMetadata("design:type", Array)
], DidCommOutOfBandInvitation.prototype, "requests", void 0);
require_decorate.__decorate([
	(0, import_cjs$1.IsArray)(),
	(0, import_cjs$1.ArrayNotEmpty)(),
	OutOfBandServiceTransformer(),
	(0, __credo_ts_core.IsStringOrInstance)(require_OutOfBandDidCommService.OutOfBandDidCommService, { each: true }),
	require_decorateMetadata.__decorateMetadata("design:type", typeof (_ref2 = typeof Array !== "undefined" && Array) === "function" ? _ref2 : Object)
], DidCommOutOfBandInvitation.prototype, "services", void 0);
require_decorate.__decorate([
	(0, import_cjs$1.IsOptional)(),
	(0, import_cjs$1.IsUrl)(),
	require_decorateMetadata.__decorateMetadata("design:type", String)
], DidCommOutOfBandInvitation.prototype, "imageUrl", void 0);
/**
* Decorator that transforms services json to corresponding class instances
* @note Because of ValidateNested limitation, this produces instances of String for DID services except plain js string
*/
function OutOfBandServiceTransformer() {
	return (0, import_cjs.Transform)(({ value, type }) => {
		if (type === import_cjs.TransformationType.PLAIN_TO_CLASS) return value.map((service) => {
			if (typeof service === "string") return new String(service);
			return __credo_ts_core.JsonTransformer.fromJSON(service, require_OutOfBandDidCommService.OutOfBandDidCommService);
		});
		if (type === import_cjs.TransformationType.CLASS_TO_PLAIN) return value.map((service) => typeof service === "string" || service instanceof String ? service.toString() : __credo_ts_core.JsonTransformer.toJSON(service));
		return value;
	});
}

//#endregion
exports.DidCommInvitationType = DidCommInvitationType;
exports.DidCommOutOfBandInvitation = DidCommOutOfBandInvitation;