const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.js');
const require_TenantRecord = require('../repository/TenantRecord.js');
const require_TenantRoutingRecord = require('../repository/TenantRoutingRecord.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_TenantRepository = require('../repository/TenantRepository.js');
const require_TenantRoutingRepository = require('../repository/TenantRoutingRepository.js');
require('../repository/index.js');
let __credo_ts_core = require("@credo-ts/core");
__credo_ts_core = require_rolldown_runtime.__toESM(__credo_ts_core);

//#region ../tenants/src/services/TenantRecordService.ts
var _ref, _ref2;
let TenantRecordService = class TenantRecordService$1 {
	constructor(tenantRepository, tenantRoutingRepository) {
		this.tenantRepository = tenantRepository;
		this.tenantRoutingRepository = tenantRoutingRepository;
	}
	async createTenant(agentContext, config) {
		const tenantRecord = new require_TenantRecord.TenantRecord({
			id: __credo_ts_core.utils.uuid(),
			config,
			storageVersion: __credo_ts_core.UpdateAssistant.frameworkStorageVersion
		});
		await this.tenantRepository.save(agentContext, tenantRecord);
		return tenantRecord;
	}
	async getTenantById(agentContext, tenantId) {
		return this.tenantRepository.getById(agentContext, tenantId);
	}
	async findTenantsByLabel(agentContext, label) {
		return this.tenantRepository.findByLabel(agentContext, label);
	}
	async getAllTenants(agentContext) {
		return this.tenantRepository.getAll(agentContext);
	}
	async deleteTenantById(agentContext, tenantId) {
		const tenantRecord = await this.getTenantById(agentContext, tenantId);
		const tenantRoutingRecords = await this.tenantRoutingRepository.findByQuery(agentContext, { tenantId: tenantRecord.id });
		await Promise.all(tenantRoutingRecords.map((tenantRoutingRecord) => this.tenantRoutingRepository.delete(agentContext, tenantRoutingRecord)));
		await this.tenantRepository.delete(agentContext, tenantRecord);
	}
	async updateTenant(agentContext, tenantRecord) {
		return this.tenantRepository.update(agentContext, tenantRecord);
	}
	async findTenantsByQuery(agentContext, query, queryOptions) {
		return this.tenantRepository.findByQuery(agentContext, query, queryOptions);
	}
	async findTenantRoutingRecordByRecipientKey(agentContext, recipientKey) {
		return this.tenantRoutingRepository.findByRecipientKey(agentContext, recipientKey);
	}
	async addTenantRoutingRecord(agentContext, tenantId, recipientKey) {
		const tenantRoutingRecord = new require_TenantRoutingRecord.TenantRoutingRecord({
			tenantId,
			recipientKeyFingerprint: recipientKey.fingerprint
		});
		await this.tenantRoutingRepository.save(agentContext, tenantRoutingRecord);
		return tenantRoutingRecord;
	}
};
TenantRecordService = require_decorate.__decorate([(0, __credo_ts_core.injectable)(), require_decorateMetadata.__decorateMetadata("design:paramtypes", [typeof (_ref = typeof require_TenantRepository.TenantRepository !== "undefined" && require_TenantRepository.TenantRepository) === "function" ? _ref : Object, typeof (_ref2 = typeof require_TenantRoutingRepository.TenantRoutingRepository !== "undefined" && require_TenantRoutingRepository.TenantRoutingRepository) === "function" ? _ref2 : Object])], TenantRecordService);

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