

const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
const require_CredoError = require('../../error/CredoError.js');
require('../../error/index.js');
require('../../plugins/index.js');
const require_decorateMetadata = require('../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.js');
const require_decorate = require('../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.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');
const require_W3cV2JwtVerifiablePresentation = require('./jwt-vc/W3cV2JwtVerifiablePresentation.js');
const require_W3cV2SdJwtVerifiablePresentation = require('./sd-jwt-vc/W3cV2SdJwtVerifiablePresentation.js');
const require_W3cV2SdJwtCredentialService = require('./sd-jwt-vc/W3cV2SdJwtCredentialService.js');
require('./sd-jwt-vc/index.js');
const require_W3cV2JwtCredentialService = require('./jwt-vc/W3cV2JwtCredentialService.js');
require('./jwt-vc/index.js');
require('./models/index.js');
const require_W3cV2CredentialRecord = require('./repository/W3cV2CredentialRecord.js');
const require_W3cV2CredentialRepository = require('./repository/W3cV2CredentialRepository.js');
require('./repository/index.js');
let tsyringe = require("tsyringe");
tsyringe = require_rolldown_runtime.__toESM(tsyringe);

//#region src/modules/vc/W3cV2CredentialService.ts
var _ref, _ref2, _ref3;
let W3cV2CredentialService = class W3cV2CredentialService$1 {
	constructor(w3cV2CredentialRepository, w3cV2SdJwtCredentialService, w3cV2JwtCredentialService) {
		this.w3cV2CredentialRepository = w3cV2CredentialRepository;
		this.w3cV2SdJwtCredentialService = w3cV2SdJwtCredentialService;
		this.w3cV2JwtCredentialService = w3cV2JwtCredentialService;
	}
	/**
	* Signs a credential
	*
	* @param credential the credential to be signed
	* @returns the signed credential
	*/
	async signCredential(agentContext, options) {
		if (options.format === require_ClaimFormat.ClaimFormat.JwtW3cVc) return await this.w3cV2JwtCredentialService.signCredential(agentContext, options);
		if (options.format === require_ClaimFormat.ClaimFormat.SdJwtW3cVc) return await this.w3cV2SdJwtCredentialService.signCredential(agentContext, options);
		throw new require_CredoError.CredoError(`Unsupported format in options. Format must be either 'vc+jwt' or 'vc+sd-jwt'`);
	}
	/**
	* Verifies the signature(s) of a credential
	*/
	async verifyCredential(agentContext, options) {
		if (options.credential instanceof require_W3cV2JwtVerifiableCredential.W3cV2JwtVerifiableCredential) return this.w3cV2JwtCredentialService.verifyCredential(agentContext, options);
		if (options.credential instanceof require_W3cV2SdJwtVerifiableCredential.W3cV2SdJwtVerifiableCredential) return this.w3cV2SdJwtCredentialService.verifyCredential(agentContext, options);
		throw new require_CredoError.CredoError("Unsupported credential type in options. Credential must be either a W3cV2JwtVerifiablePresentation or a W3cV2SdJwtVerifiablePresentation");
	}
	/**
	* Signs a presentation including the credentials it includes
	*
	* @param presentation the presentation to be signed
	* @returns the signed presentation
	*/
	async signPresentation(agentContext, options) {
		if (options.format === require_ClaimFormat.ClaimFormat.JwtW3cVp) return await this.w3cV2JwtCredentialService.signPresentation(agentContext, options);
		if (options.format === require_ClaimFormat.ClaimFormat.SdJwtW3cVp) return await this.w3cV2SdJwtCredentialService.signPresentation(agentContext, options);
		throw new require_CredoError.CredoError(`Unsupported format in options. Format must be either 'vp+jwt' or 'vp+sd-jwt'`);
	}
	/**
	* Verifies a presentation including the credentials it includes
	*
	* @param presentation the presentation to be verified
	* @returns the verification result
	*/
	async verifyPresentation(agentContext, options) {
		if (options.presentation instanceof require_W3cV2JwtVerifiablePresentation.W3cV2JwtVerifiablePresentation) return this.w3cV2JwtCredentialService.verifyPresentation(agentContext, options);
		if (options.presentation instanceof require_W3cV2SdJwtVerifiablePresentation.W3cV2SdJwtVerifiablePresentation) return this.w3cV2SdJwtCredentialService.verifyPresentation(agentContext, options);
		throw new require_CredoError.CredoError("Unsupported credential type in options. Presentation must be either a W3cV2JwtVerifiablePresentation or a W3cV2SdJwtVerifiablePresentation");
	}
	/**
	* Writes a credential to storage
	*
	* @param record the credential to be stored
	* @returns the credential record that was written to storage
	*/
	async storeCredential(agentContext, options) {
		const w3cV2CredentialRecord = new require_W3cV2CredentialRecord.W3cV2CredentialRecord({ credential: options.credential });
		await this.w3cV2CredentialRepository.save(agentContext, w3cV2CredentialRecord);
		return w3cV2CredentialRecord;
	}
	async removeCredentialRecord(agentContext, id) {
		await this.w3cV2CredentialRepository.deleteById(agentContext, id);
	}
	async getAllCredentialRecords(agentContext) {
		return await this.w3cV2CredentialRepository.getAll(agentContext);
	}
	async getCredentialRecordById(agentContext, id) {
		return await this.w3cV2CredentialRepository.getById(agentContext, id);
	}
	async findCredentialsByQuery(agentContext, query, queryOptions) {
		return (await this.w3cV2CredentialRepository.findByQuery(agentContext, query, queryOptions)).map((record) => record.credential);
	}
	async findCredentialRecordByQuery(agentContext, query) {
		return (await this.w3cV2CredentialRepository.findSingleByQuery(agentContext, query))?.credential;
	}
};
W3cV2CredentialService = require_decorate.__decorate([(0, tsyringe.injectable)(), require_decorateMetadata.__decorateMetadata("design:paramtypes", [
	typeof (_ref = typeof require_W3cV2CredentialRepository.W3cV2CredentialRepository !== "undefined" && require_W3cV2CredentialRepository.W3cV2CredentialRepository) === "function" ? _ref : Object,
	typeof (_ref2 = typeof require_W3cV2SdJwtCredentialService.W3cV2SdJwtCredentialService !== "undefined" && require_W3cV2SdJwtCredentialService.W3cV2SdJwtCredentialService) === "function" ? _ref2 : Object,
	typeof (_ref3 = typeof require_W3cV2JwtCredentialService.W3cV2JwtCredentialService !== "undefined" && require_W3cV2JwtCredentialService.W3cV2JwtCredentialService) === "function" ? _ref3 : Object
])], W3cV2CredentialService);

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