

import { __decorateMetadata } from "../../../_virtual/_@oxc-project_runtime@0.95.0/helpers/decorateMetadata.mjs";
import { __decorate } from "../../../_virtual/_@oxc-project_runtime@0.95.0/helpers/decorate.mjs";
import { asArray } from "../../../utils/array.mjs";
import { JsonTransformer } from "../../../utils/JsonTransformer.mjs";
import "../../../utils/index.mjs";
import { BaseRecord } from "../../../storage/BaseRecord.mjs";
import { uuid } from "../../../utils/uuid.mjs";
import { ClaimFormat } from "../models/ClaimFormat.mjs";
import { W3cV2EnvelopedVerifiableCredential } from "../models/credential/W3cV2EnvelopedVerifiableCredential.mjs";
import { W3cV2VerifiableCredentialTransformer } from "../models/credential/W3cV2VerifiableCredential.mjs";
import "../models/index.mjs";

//#region src/modules/vc/repository/W3cV2CredentialRecord.ts
var W3cV2CredentialRecord = class W3cV2CredentialRecord extends BaseRecord {
	constructor(props) {
		super();
		this.type = W3cV2CredentialRecord.type;
		if (props) {
			this.id = props.id ?? uuid();
			this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
			this.credential = props.credential;
		}
	}
	getTags() {
		const resolvedCredential = this.credential.resolvedCredential;
		const stringContexts = resolvedCredential.contexts.filter((ctx) => typeof ctx === "string");
		const tags = {
			...this._tags,
			issuerId: resolvedCredential.issuerId,
			subjectIds: resolvedCredential.credentialSubjectIds,
			schemaIds: resolvedCredential.credentialSchemaIds,
			contexts: stringContexts,
			givenId: resolvedCredential.id,
			claimFormat: this.credential.claimFormat,
			types: asArray(resolvedCredential.type)
		};
		if (this.credential instanceof W3cV2EnvelopedVerifiableCredential) {
			const enveloped = this.credential.envelopedCredential;
			if (enveloped.claimFormat === ClaimFormat.JwtW3cVc) tags.algs = [enveloped.jwt.header.alg];
			else if (enveloped.claimFormat === ClaimFormat.SdJwtW3cVc) tags.algs = [enveloped.sdJwt.header.alg];
		}
		return tags;
	}
	/**
	* This overwrites the default `clone` method for records, as the W3cV3CredentialRecord
	* has issues with the default clone method due to the way the JWT and SD-JWT
	* records are implemented. This is a temporary way to make sure the clone still works, but ideally
	* we find an alternative.
	*/
	clone() {
		return JsonTransformer.fromJSON(JsonTransformer.toJSON(this), this.constructor);
	}
	/**
	* encoded is convenience method added to all credential records
	*/
	get encoded() {
		return this.credential.encoded;
	}
};
W3cV2CredentialRecord.type = "W3cV2CredentialRecord";
__decorate([W3cV2VerifiableCredentialTransformer(), __decorateMetadata("design:type", Object)], W3cV2CredentialRecord.prototype, "credential", void 0);

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