

const require_array = require('../../../utils/array.js');
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_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');
require('../models/index.js');

//#region src/modules/vc/repository/W3cV2CredentialRecord.ts
var W3cV2CredentialRecord = class W3cV2CredentialRecord extends require_BaseRecord.BaseRecord {
	constructor(props) {
		super();
		this.type = W3cV2CredentialRecord.type;
		this.multiInstanceState = require_credentialUseTypes.CredentialMultiInstanceState.SingleInstanceUsed;
		if (props) {
			this.id = props.id ?? require_uuid.uuid();
			this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
			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 credential.includes("~") ? require_W3cV2SdJwtVerifiableCredential.W3cV2SdJwtVerifiableCredential.fromCompact(credential) : require_W3cV2JwtVerifiableCredential.W3cV2JwtVerifiableCredential.fromCompact(credential);
	}
	static fromCredential(credential) {
		return new W3cV2CredentialRecord({ credentialInstances: [{ credential: credential.encoded }] });
	}
	getTags() {
		const credential = this.firstCredential;
		const resolvedCredential = 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: credential.claimFormat,
			types: require_array.asArray(resolvedCredential.type),
			multiInstanceState: this.multiInstanceState
		};
		if (credential.claimFormat === require_ClaimFormat.ClaimFormat.JwtW3cVc) tags.algs = [credential.jwt.header.alg];
		else if (credential.claimFormat === require_ClaimFormat.ClaimFormat.SdJwtW3cVc) tags.algs = [credential.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 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;
	}
};
W3cV2CredentialRecord.type = "W3cV2CredentialRecord";

//#endregion
exports.W3cV2CredentialRecord = W3cV2CredentialRecord;