const require_rolldown_runtime = require('../../../../../_virtual/rolldown_runtime.js');
const require_DidCommConnectionInvitationMessage = require('../connections/messages/DidCommConnectionInvitationMessage.js');
const require_OutOfBandDidCommService = require('./domain/OutOfBandDidCommService.js');
const require_DidCommOutOfBandInvitation = require('./messages/DidCommOutOfBandInvitation.js');
let __credo_ts_core = require("@credo-ts/core");
__credo_ts_core = require_rolldown_runtime.__toESM(__credo_ts_core);

//#region ../didcomm/src/modules/oob/converters.ts
function convertToNewInvitation(oldInvitation) {
	let service;
	if (oldInvitation.did) service = oldInvitation.did;
	else if (oldInvitation.serviceEndpoint && oldInvitation.recipientKeys && oldInvitation.recipientKeys.length > 0) service = new require_OutOfBandDidCommService.OutOfBandDidCommService({
		id: "#inline",
		recipientKeys: oldInvitation.recipientKeys?.map(__credo_ts_core.verkeyToDidKey),
		routingKeys: oldInvitation.routingKeys?.map(__credo_ts_core.verkeyToDidKey),
		serviceEndpoint: oldInvitation.serviceEndpoint
	});
	else throw new Error("Missing required serviceEndpoint, routingKeys and/or did fields in connection invitation");
	const outOfBandInvitation = new require_DidCommOutOfBandInvitation.DidCommOutOfBandInvitation({
		id: oldInvitation.id,
		label: oldInvitation.label,
		imageUrl: oldInvitation.imageUrl,
		appendedAttachments: oldInvitation.appendedAttachments,
		accept: ["didcomm/aip1", "didcomm/aip2;env=rfc19"],
		services: [service],
		handshakeProtocols: ["https://didcomm.org/connections/1.0"]
	});
	outOfBandInvitation.invitationType = require_DidCommOutOfBandInvitation.DidCommInvitationType.Connection;
	return outOfBandInvitation;
}
function convertToOldInvitation(newInvitation) {
	const [service] = newInvitation.getServices();
	let options;
	if (typeof service === "string") options = {
		id: newInvitation.id,
		label: newInvitation.label ?? "",
		did: service,
		imageUrl: newInvitation.imageUrl,
		appendedAttachments: newInvitation.appendedAttachments
	};
	else options = {
		id: newInvitation.id,
		label: newInvitation.label ?? "",
		recipientKeys: service.recipientKeys.map(__credo_ts_core.didKeyToVerkey),
		routingKeys: service.routingKeys?.map(__credo_ts_core.didKeyToVerkey),
		serviceEndpoint: service.serviceEndpoint,
		imageUrl: newInvitation.imageUrl,
		appendedAttachments: newInvitation.appendedAttachments
	};
	return new require_DidCommConnectionInvitationMessage.DidCommConnectionInvitationMessage(options);
}

//#endregion
exports.convertToNewInvitation = convertToNewInvitation;
exports.convertToOldInvitation = convertToOldInvitation;