

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_W3cV2JwtVerifiableCredential = require('../../jwt-vc/W3cV2JwtVerifiableCredential.js');
const require_W3cV2SdJwtVerifiableCredential = require('../../sd-jwt-vc/W3cV2SdJwtVerifiableCredential.js');
require('../../sd-jwt-vc/index.js');
require('../../jwt-vc/index.js');
let class_transformer = require("class-transformer");
let class_validator = require("class-validator");

//#region src/modules/vc/models/credential/W3cV2VerifiableCredential.ts
const decodeCredential = (v) => {
	try {
		if (typeof v !== "string") throw new require_CredoError.CredoError("Expected a plain string encoding");
		if (v.includes("~")) return require_W3cV2SdJwtVerifiableCredential.W3cV2SdJwtVerifiableCredential.fromCompact(v);
		return require_W3cV2JwtVerifiableCredential.W3cV2JwtVerifiableCredential.fromCompact(v);
	} 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 W3cV2VerifiableCredential. ${error.message}`);
	}
};
const encodeCredential = (v) => {
	if (v instanceof require_W3cV2JwtVerifiableCredential.W3cV2JwtVerifiableCredential) return v.encoded;
	if (v instanceof require_W3cV2SdJwtVerifiableCredential.W3cV2SdJwtVerifiableCredential) return v.encoded;
	throw new require_CredoError.CredoError(`Value '${v}' is not a valid W3cV2VerifiableCredential`);
};
function W3cV2VerifiableCredentialTransformer() {
	return (0, class_transformer.Transform)(({ value, type }) => {
		if (type === class_transformer.TransformationType.PLAIN_TO_CLASS) return Array.isArray(value) ? value.map(decodeCredential) : decodeCredential(value);
		if (type === class_transformer.TransformationType.CLASS_TO_PLAIN) {
			if (Array.isArray(value)) return value.map(encodeCredential);
			return encodeCredential(value);
		}
		return value;
	});
}

//#endregion
exports.W3cV2VerifiableCredentialTransformer = W3cV2VerifiableCredentialTransformer;