

const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.js');
const require_CredoError = require('../../../../error/CredoError.js');
const require_ClassValidationError = require('../../../../error/ClassValidationError.js');
require('../../../../error/index.js');
const require_JsonTransformer = require('../../../../utils/JsonTransformer.js');
require('../../../../utils/index.js');
const require_W3cJsonLdVerifiableCredential = require('../../data-integrity/models/W3cJsonLdVerifiableCredential.js');
const require_W3cJwtVerifiableCredential = require('../../jwt-vc/W3cJwtVerifiableCredential.js');
let class_transformer = require("class-transformer");
class_transformer = require_rolldown_runtime.__toESM(class_transformer);
let class_validator = require("class-validator");
class_validator = require_rolldown_runtime.__toESM(class_validator);

//#region src/modules/vc/models/credential/W3cVerifiableCredential.ts
const getCredential = (v) => {
	try {
		return typeof v === "string" ? require_W3cJwtVerifiableCredential.W3cJwtVerifiableCredential.fromSerializedJwt(v) : require_JsonTransformer.JsonTransformer.fromJSON(v, require_W3cJsonLdVerifiableCredential.W3cJsonLdVerifiableCredential, { validate: false });
	} catch (error) {
		if (error instanceof class_validator.ValidationError || error instanceof require_ClassValidationError.ClassValidationError) throw error;
		throw new require_CredoError.CredoError(`value '${v}' is not a valid W3cJwtVerifiableCredential. ${error.message}`);
	}
};
const getEncoded = (v) => v instanceof require_W3cJwtVerifiableCredential.W3cJwtVerifiableCredential ? v.serializedJwt : require_JsonTransformer.JsonTransformer.toJSON(v);
function W3cVerifiableCredentialTransformer() {
	return (0, class_transformer.Transform)(({ value, type }) => {
		if (type === class_transformer.TransformationType.PLAIN_TO_CLASS) return Array.isArray(value) ? value.map(getCredential) : getCredential(value);
		if (type === class_transformer.TransformationType.CLASS_TO_PLAIN) {
			if (Array.isArray(value)) return value.map(getEncoded);
			return getEncoded(value);
		}
		return value;
	});
}

//#endregion
exports.W3cVerifiableCredentialTransformer = W3cVerifiableCredentialTransformer;