import { __decorateMetadata } from "../../../../../../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.mjs";
import { __decorate } from "../../../../../../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.mjs";
import { IsValidMessageType, parseMessageType, replaceLegacyDidSovPrefix } from "../../../../../util/messageType.mjs";
import { DidCommCredentialPreviewAttribute } from "../../../models/DidCommCredentialPreviewAttribute.mjs";
import { JsonTransformer } from "@credo-ts/core";
import { Expose, Transform, Type } from "class-transformer";
import { IsInstance, ValidateNested } from "class-validator";

//#region ../didcomm/src/modules/credentials/protocol/v2/messages/DidCommCredentialV2Preview.ts
/**
* Credential preview inner message class.
*
* This is not a message but an inner object for other messages in this protocol. It is used construct a preview of the data for the credential.
*
* @see https://github.com/hyperledger/aries-rfcs/tree/main/features/0453-issue-credential-v2#preview-credential
*/
var DidCommCredentialV2Preview = class DidCommCredentialV2Preview {
	constructor(options) {
		this.type = DidCommCredentialV2Preview.type.messageTypeUri;
		if (options) this.attributes = options.attributes.map((a) => new DidCommCredentialPreviewAttribute(a));
	}
	toJSON() {
		return JsonTransformer.toJSON(this);
	}
	/**
	* Create a credential preview from a record with name and value entries.
	*
	* @example
	* const preview = CredentialPreview.fromRecord({
	*   name: "Bob",
	*   age: "20"
	* })
	*/
	static fromRecord(record) {
		return new DidCommCredentialV2Preview({ attributes: Object.entries(record).map(([name, value]) => new DidCommCredentialPreviewAttribute({
			name,
			mimeType: "text/plain",
			value
		})) });
	}
};
DidCommCredentialV2Preview.type = parseMessageType("https://didcomm.org/issue-credential/2.0/credential-preview");
__decorate([
	Expose({ name: "@type" }),
	IsValidMessageType(DidCommCredentialV2Preview.type),
	Transform(({ value }) => replaceLegacyDidSovPrefix(value), { toClassOnly: true }),
	__decorateMetadata("design:type", Object)
], DidCommCredentialV2Preview.prototype, "type", void 0);
__decorate([
	Type(() => DidCommCredentialPreviewAttribute),
	ValidateNested({ each: true }),
	IsInstance(DidCommCredentialPreviewAttribute, { each: true }),
	__decorateMetadata("design:type", Array)
], DidCommCredentialV2Preview.prototype, "attributes", void 0);

//#endregion
export { DidCommCredentialV2Preview };
//# sourceMappingURL=DidCommCredentialV2Preview.mjs.map