

import { InjectionSymbols } from "../../../constants.mjs";
import { inject, injectable } from "../../../plugins/index.mjs";
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 "../../kms/index.mjs";
import { DidDocumentRole } from "../domain/DidDocumentRole.mjs";
import { DidRecord } from "./DidRecord.mjs";
import { __decorateParam } from "../../../_virtual/_@oxc-project_runtime@0.95.0/helpers/decorateParam.mjs";
import { EventEmitter } from "../../../agent/EventEmitter.mjs";
import { Repository } from "../../../storage/Repository.mjs";

//#region src/modules/dids/repository/DidRepository.ts
var _ref;
let DidRepository = class DidRepository$1 extends Repository {
	constructor(storageService, eventEmitter) {
		super(DidRecord, storageService, eventEmitter);
	}
	/**
	* Finds a {@link DidRecord}, containing the specified recipientKey that was received by this agent.
	* To find a {@link DidRecord} that was created by this agent, use {@link DidRepository.findCreatedDidByRecipientKey}.
	*/
	findReceivedDidByRecipientKey(agentContext, recipientKey) {
		return this.findSingleByQuery(agentContext, {
			recipientKeyFingerprints: [recipientKey.fingerprint],
			role: DidDocumentRole.Received
		});
	}
	/**
	* Finds a {@link DidRecord}, containing the specified recipientKey that was created by this agent.
	* To find a {@link DidRecord} that was received by this agent, use {@link DidRepository.findReceivedDidByRecipientKey}.
	*/
	findCreatedDidByRecipientKey(agentContext, recipientKey) {
		return this.findSingleByQuery(agentContext, {
			recipientKeyFingerprints: [recipientKey.fingerprint],
			role: DidDocumentRole.Created
		});
	}
	findAllByRecipientKey(agentContext, recipientKey) {
		return this.findByQuery(agentContext, { recipientKeyFingerprints: [recipientKey.fingerprint] });
	}
	findAllByDid(agentContext, did) {
		return this.findByQuery(agentContext, { $or: [{ alternativeDids: [did] }, { did }] });
	}
	findReceivedDid(agentContext, receivedDid) {
		return this.findSingleByQuery(agentContext, {
			$or: [{ alternativeDids: [receivedDid] }, { did: receivedDid }],
			role: DidDocumentRole.Received
		});
	}
	findCreatedDid(agentContext, createdDid) {
		return this.findSingleByQuery(agentContext, {
			$or: [{ alternativeDids: [createdDid] }, { did: createdDid }],
			role: DidDocumentRole.Created
		});
	}
	getCreatedDids(agentContext, { method, did }) {
		return this.findByQuery(agentContext, {
			role: DidDocumentRole.Created,
			method,
			$or: did ? [{ alternativeDids: [did] }, { did }] : void 0
		});
	}
	async storeCreatedDid(agentContext, { did, didDocument, tags, keys }) {
		const didRecord = new DidRecord({
			did,
			didDocument,
			role: DidDocumentRole.Created,
			tags,
			keys
		});
		await this.save(agentContext, didRecord);
		return didRecord;
	}
	async storeReceivedDid(agentContext, { did, didDocument, tags }) {
		const didRecord = new DidRecord({
			did,
			didDocument,
			role: DidDocumentRole.Received,
			tags
		});
		await this.save(agentContext, didRecord);
		return didRecord;
	}
};
DidRepository = __decorate([
	injectable(),
	__decorateParam(0, inject(InjectionSymbols.StorageService)),
	__decorateMetadata("design:paramtypes", [Object, typeof (_ref = typeof EventEmitter !== "undefined" && EventEmitter) === "function" ? _ref : Object])
], DidRepository);

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