

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_Mdoc = require('../Mdoc.js');

//#region src/modules/mdoc/repository/MdocRecord.ts
var MdocRecord = class MdocRecord extends require_BaseRecord.BaseRecord {
	/**
	* Only here for class transformation. If base64Url is set we transform
	* it to the new mdocs array format
	*/
	set base64Url(base64Url) {
		this.credentialInstances = [{ issuerSignedBase64Url: base64Url }];
	}
	constructor(props) {
		super();
		this.type = MdocRecord.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;
			this._tags = props.tags ?? {};
		}
	}
	get firstCredential() {
		const mdoc = require_Mdoc.Mdoc.fromBase64Url(this.credentialInstances[0].issuerSignedBase64Url);
		mdoc.deviceKeyId = this.credentialInstances[0].kmsKeyId ?? mdoc.deviceKey?.legacyKeyId;
		return mdoc;
	}
	static fromMdoc(mdoc) {
		return new MdocRecord({ credentialInstances: [{
			issuerSignedBase64Url: mdoc.base64Url,
			kmsKeyId: mdoc.deviceKeyId
		}] });
	}
	getTags() {
		const mdoc = this.firstCredential;
		const docType = mdoc.docType;
		const alg = mdoc.alg;
		return {
			...this._tags,
			docType,
			alg,
			multiInstanceState: this.multiInstanceState
		};
	}
	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].issuerSignedBase64Url;
	}
};
MdocRecord.type = "MdocRecord";

//#endregion
exports.MdocRecord = MdocRecord;