

const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.js');
const require_constants = require('../../../constants.js');
require('../../../plugins/index.js');
const require_decorateMetadata = require('../../../_virtual/_@oxc-project_runtime@0.97.0/helpers/decorateMetadata.js');
const require_decorate = require('../../../_virtual/_@oxc-project_runtime@0.97.0/helpers/decorate.js');
require('../../kms/index.js');
const require_DidDocumentRole = require('../domain/DidDocumentRole.js');
const require_DidRecord = require('./DidRecord.js');
const require_decorateParam = require('../../../_virtual/_@oxc-project_runtime@0.97.0/helpers/decorateParam.js');
const require_EventEmitter = require('../../../agent/EventEmitter.js');
const require_Repository = require('../../../storage/Repository.js');
let tsyringe = require("tsyringe");

//#region src/modules/dids/repository/DidRepository.ts
var _ref;
let DidRepository = class DidRepository$1 extends require_Repository.Repository {
	constructor(storageService, eventEmitter) {
		super(require_DidRecord.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: require_DidDocumentRole.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: require_DidDocumentRole.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: require_DidDocumentRole.DidDocumentRole.Received
		});
	}
	findCreatedDid(agentContext, createdDid) {
		return this.findSingleByQuery(agentContext, {
			$or: [{ alternativeDids: [createdDid] }, { did: createdDid }],
			role: require_DidDocumentRole.DidDocumentRole.Created
		});
	}
	getCreatedDids(agentContext, { method, did }) {
		return this.findByQuery(agentContext, {
			role: require_DidDocumentRole.DidDocumentRole.Created,
			method,
			$or: did ? [{ alternativeDids: [did] }, { did }] : void 0
		});
	}
	async storeCreatedDid(agentContext, { did, didDocument, tags, keys }) {
		const didRecord = new require_DidRecord.DidRecord({
			did,
			didDocument,
			role: require_DidDocumentRole.DidDocumentRole.Created,
			tags,
			keys
		});
		await this.save(agentContext, didRecord);
		return didRecord;
	}
	async storeReceivedDid(agentContext, { did, didDocument, tags }) {
		const didRecord = new require_DidRecord.DidRecord({
			did,
			didDocument,
			role: require_DidDocumentRole.DidDocumentRole.Received,
			tags
		});
		await this.save(agentContext, didRecord);
		return didRecord;
	}
};
DidRepository = require_decorate.__decorate([
	(0, tsyringe.injectable)(),
	require_decorateParam.__decorateParam(0, (0, tsyringe.inject)(require_constants.InjectionSymbols.StorageService)),
	require_decorateMetadata.__decorateMetadata("design:paramtypes", [Object, typeof (_ref = typeof require_EventEmitter.EventEmitter !== "undefined" && require_EventEmitter.EventEmitter) === "function" ? _ref : Object])
], DidRepository);

//#endregion
Object.defineProperty(exports, 'DidRepository', {
  enumerable: true,
  get: function () {
    return DidRepository;
  }
});