

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');
let class_transformer = require("class-transformer");
let class_validator = require("class-validator");

//#region src/modules/vc/models/credential/W3cCredentialSubject.ts
var _ref;
var W3cCredentialSubject = class {
	constructor(options) {
		if (options) {
			this.id = options.id;
			const { id, ...claims } = options.claims ?? {};
			this.claims = Object.keys(claims).length > 0 ? claims : void 0;
		}
	}
};
require_decorate.__decorate([(0, class_validator.IsOptional)(), require_decorateMetadata.__decorateMetadata("design:type", String)], W3cCredentialSubject.prototype, "id", void 0);
require_decorate.__decorate([(0, class_validator.IsOptional)(), require_decorateMetadata.__decorateMetadata("design:type", typeof (_ref = typeof Record !== "undefined" && Record) === "function" ? _ref : Object)], W3cCredentialSubject.prototype, "claims", void 0);
function W3cCredentialSubjectTransformer() {
	return (0, class_transformer.Transform)(({ value, type }) => {
		if (type === class_transformer.TransformationType.PLAIN_TO_CLASS) {
			const vToClass = (v) => {
				if (!v || typeof v !== "object") throw new require_CredoError.CredoError("Invalid credential subject");
				if ((0, class_validator.isInstance)(v, W3cCredentialSubject)) return v;
				const { id, ...claims } = v;
				if (id !== void 0 && typeof id !== "string") throw new require_CredoError.CredoError("Invalid credential subject id");
				return new W3cCredentialSubject({
					id,
					claims
				});
			};
			if (Array.isArray(value) && value.length === 0) throw new require_CredoError.CredoError("At least one credential subject is required");
			return Array.isArray(value) ? value.map(vToClass) : vToClass(value);
		}
		if (type === class_transformer.TransformationType.CLASS_TO_PLAIN) {
			const vToJson = (v) => {
				if (v instanceof W3cCredentialSubject) return v.id ? {
					...v.claims,
					id: v.id
				} : { ...v.claims };
				return v;
			};
			return Array.isArray(value) ? value.map(vToJson) : vToJson(value);
		}
		return value;
	});
}
function IsW3cCredentialSubject(validationOptions) {
	return (0, class_validator.ValidateBy)({
		name: "IsW3cCredentialSubject",
		validator: {
			validate: (value) => {
				return (0, class_validator.isInstance)(value, W3cCredentialSubject);
			},
			defaultMessage: (0, class_validator.buildMessage)((eachPrefix) => `${eachPrefix}$property must be an object or an array of objects with an optional id property`, validationOptions)
		}
	}, validationOptions);
}

//#endregion
exports.IsW3cCredentialSubject = IsW3cCredentialSubject;
exports.W3cCredentialSubject = W3cCredentialSubject;
exports.W3cCredentialSubjectTransformer = W3cCredentialSubjectTransformer;