

const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.js');
const require_CredoError = require('../../../../error/CredoError.js');
require('../../../../error/index.js');
const require_decorateMetadata = require('../../../../_virtual/_@oxc-project_runtime@0.97.0/helpers/decorateMetadata.js');
const require_decorate = require('../../../../_virtual/_@oxc-project_runtime@0.97.0/helpers/decorate.js');
const require_constants = require('../../constants.js');
const require_validators = require('../../validators.js');
require('./W3cV2Presentation.js');
const require_W3cV2SdJwtVerifiablePresentation = require('../../sd-jwt-vc/W3cV2SdJwtVerifiablePresentation.js');
require('../../sd-jwt-vc/index.js');
const require_W3cV2JwtVerifiablePresentation = require('../../jwt-vc/W3cV2JwtVerifiablePresentation.js');
require('../../jwt-vc/index.js');
let class_transformer = require("class-transformer");
let class_validator = require("class-validator");

//#region src/modules/vc/models/presentation/W3cV2EnvelopedVerifiablePresentation.ts
var W3cV2EnvelopedVerifiablePresentation = class W3cV2EnvelopedVerifiablePresentation {
	constructor(options) {
		if (options) {
			this.context = options.context ?? require_constants.CREDENTIALS_CONTEXT_V2_URL;
			this.id = options.id;
			this.type = options.type ?? require_constants.ENVELOPED_VERIFIABLE_CREDENTIAL_TYPE;
			this._envelopedPresentation = presentationFromDataUri(options.id);
		}
	}
	static fromVerifiablePresentation(presentation) {
		return new W3cV2EnvelopedVerifiablePresentation({
			id: presentationToDataUri(presentation),
			context: require_constants.CREDENTIALS_CONTEXT_V2_URL,
			type: require_constants.ENVELOPED_VERIFIABLE_PRESENTATION_TYPE
		});
	}
	/**
	* Gets the enveloped presentation.
	*/
	get envelopedPresentation() {
		if (!this._envelopedPresentation) this._envelopedPresentation = presentationFromDataUri(this.id);
		return this._envelopedPresentation;
	}
	/**
	* Resolved presentation is the fully resolved {@link W3cV2Presentation} instance.
	*/
	get resolvedPresentation() {
		return this.envelopedPresentation.resolvedPresentation;
	}
	/**
	* The {@link ClaimFormat} of the enveloped presentation.
	*/
	get claimFormat() {
		return this.envelopedPresentation.claimFormat;
	}
};
require_decorate.__decorate([(0, class_transformer.Exclude)(), require_decorateMetadata.__decorateMetadata("design:type", Object)], W3cV2EnvelopedVerifiablePresentation.prototype, "_envelopedPresentation", void 0);
require_decorate.__decorate([
	(0, class_transformer.Expose)({ name: "@context" }),
	require_validators.IsCredentialJsonLdContext({
		allowString: true,
		credentialContext: require_constants.CREDENTIALS_CONTEXT_V2_URL
	}),
	require_decorateMetadata.__decorateMetadata("design:type", Object)
], W3cV2EnvelopedVerifiablePresentation.prototype, "context", void 0);
require_decorate.__decorate([(0, class_validator.IsDataURI)(), require_decorateMetadata.__decorateMetadata("design:type", String)], W3cV2EnvelopedVerifiablePresentation.prototype, "id", void 0);
require_decorate.__decorate([IsEnvelopedVerifiablePresentationType(), require_decorateMetadata.__decorateMetadata("design:type", Object)], W3cV2EnvelopedVerifiablePresentation.prototype, "type", void 0);
function IsEnvelopedVerifiablePresentationType(validationOptions) {
	return (0, class_validator.ValidateBy)({
		name: "IsEnvelopedVerifiablePresentationType",
		validator: {
			validate: (value) => {
				return Array.isArray(value) ? value.includes(require_constants.ENVELOPED_VERIFIABLE_PRESENTATION_TYPE) : value === require_constants.ENVELOPED_VERIFIABLE_PRESENTATION_TYPE;
			},
			defaultMessage: (0, class_validator.buildMessage)((eachPrefix) => `${eachPrefix}$property must be a string that equals, or an array of strings which includes "${require_constants.ENVELOPED_VERIFIABLE_PRESENTATION_TYPE}"`, validationOptions)
		}
	}, validationOptions);
}
function presentationFromDataUri(uri) {
	if (!uri.startsWith("data:")) throw new require_CredoError.CredoError("Invalid Enveloped Verifiable Presentation: \"id\" is not a valid data URI");
	const mimetypeData = uri.slice(5);
	const commaIndex = mimetypeData.indexOf(",");
	if (commaIndex === -1) throw new require_CredoError.CredoError("Invalid Enveloped Verifiable Presentation: \"id\" data URI is missing comma separator");
	const mimetype = mimetypeData.slice(0, commaIndex);
	const data = mimetypeData.slice(commaIndex + 1);
	switch (mimetype) {
		case "application/vp+sd-jwt": return require_W3cV2SdJwtVerifiablePresentation.W3cV2SdJwtVerifiablePresentation.fromCompact(data);
		case "application/vp+jwt": return require_W3cV2JwtVerifiablePresentation.W3cV2JwtVerifiablePresentation.fromCompact(data);
		default: throw new require_CredoError.CredoError(`Unsupported Enveloped Verifiable Presentation: ${mimetype} not recognized`);
	}
}
function presentationToDataUri(presentation) {
	if (presentation instanceof require_W3cV2SdJwtVerifiablePresentation.W3cV2SdJwtVerifiablePresentation) return `data:application/vp+sd-jwt,${presentation.encoded}`;
	if (presentation instanceof require_W3cV2JwtVerifiablePresentation.W3cV2JwtVerifiablePresentation) return `data:application/vp+jwt,${presentation.encoded}`;
	throw new require_CredoError.CredoError("Unsupported Verifiable Presentation instance");
}

//#endregion
exports.IsEnvelopedVerifiablePresentationType = IsEnvelopedVerifiablePresentationType;
exports.W3cV2EnvelopedVerifiablePresentation = W3cV2EnvelopedVerifiablePresentation;