

const require_JsonTransformer = require('../../../utils/JsonTransformer.js');
require('../../../utils/index.js');
const require_BaseRecord = require('../../../storage/BaseRecord.js');
const require_uuid = require('../../../utils/uuid.js');
const require_credentialUseTypes = require('../../../utils/credentialUseTypes.js');
const require_ClaimFormat = require('../models/ClaimFormat.js');
const require_W3cJsonLdVerifiableCredential = require('../data-integrity/models/W3cJsonLdVerifiableCredential.js');
const require_W3cJwtVerifiableCredential = require('../jwt-vc/W3cJwtVerifiableCredential.js');
require('../jwt-vc/index.js');
require('../models/index.js');
require('../data-integrity/index.js');

//#region src/modules/vc/repository/W3cCredentialRecord.ts
var W3cCredentialRecord = class W3cCredentialRecord extends require_BaseRecord.BaseRecord {
	constructor(props) {
		super();
		this.type = W3cCredentialRecord.type;
		this.multiInstanceState = require_credentialUseTypes.CredentialMultiInstanceState.SingleInstanceUsed;
		if (props) {
			this.id = props.id ?? require_uuid.uuid();
			this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
			this._tags = props.tags ?? {};
			this.credentialInstances = props.credentialInstances;
			this.multiInstanceState = this.credentialInstances.length === 1 ? require_credentialUseTypes.CredentialMultiInstanceState.SingleInstanceUnused : require_credentialUseTypes.CredentialMultiInstanceState.MultiInstanceFirstUnused;
		}
	}
	/**
	* Only here for class transformation. If credential is set we transform
	* it to the new credentialInstances array format
	*/
	set credential(credential) {
		this.credentialInstances = [{ credential }];
	}
	get firstCredential() {
		const credential = this.credentialInstances[0].credential;
		return typeof credential === "string" ? require_W3cJwtVerifiableCredential.W3cJwtVerifiableCredential.fromSerializedJwt(credential) : require_W3cJsonLdVerifiableCredential.W3cJsonLdVerifiableCredential.fromJson(credential);
	}
	static fromCredential(credential) {
		return new W3cCredentialRecord({
			credentialInstances: [{ credential: credential.encoded }],
			tags: {}
		});
	}
	getTags() {
		const credential = this.firstCredential;
		const stringContexts = credential.contexts.filter((ctx) => typeof ctx === "string");
		const tags = {
			...this._tags,
			issuerId: credential.issuerId,
			subjectIds: credential.credentialSubjectIds,
			schemaIds: credential.credentialSchemaIds,
			contexts: stringContexts,
			givenId: credential.id,
			claimFormat: credential.claimFormat,
			types: credential.type,
			multiInstanceState: this.multiInstanceState
		};
		if (credential.claimFormat === require_ClaimFormat.ClaimFormat.LdpVc) {
			tags.proofTypes = credential.proofTypes;
			tags.cryptosuites = credential.dataIntegrityCryptosuites;
		} else if (credential.claimFormat === require_ClaimFormat.ClaimFormat.JwtVc) tags.algs = [credential.jwt.header.alg];
		return tags;
	}
	/**
	* This overwrites the default clone method for records
	* as the W3cRecord has issues with the default clone method
	* due to how W3cJwtVerifiableCredential is implemented. This is
	* a temporary way to make sure the clone still works, but ideally
	* we find an alternative.
	*/
	clone() {
		return require_JsonTransformer.JsonTransformer.fromJSON(require_JsonTransformer.JsonTransformer.toJSON(this), this.constructor);
	}
	/**
	* encoded is convenience method added to all credential records
	*/
	get encoded() {
		return this.credentialInstances[0].credential;
	}
};
W3cCredentialRecord.type = "W3cCredentialRecord";

//#endregion
exports.W3cCredentialRecord = W3cCredentialRecord;