const require_rolldown_runtime = require('../../../../../../_virtual/rolldown_runtime.js');
const require_index = require('../../../../../../node_modules/.pnpm/class-transformer@0.5.1/node_modules/class-transformer/cjs/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_DidCommMediationState = require('../models/DidCommMediationState.js');
const require_DidCommMediatorPickupStrategy = require('../DidCommMediatorPickupStrategy.js');
let __credo_ts_core = require("@credo-ts/core");
__credo_ts_core = require_rolldown_runtime.__toESM(__credo_ts_core);

//#region ../didcomm/src/modules/routing/repository/DidCommMediationRecord.ts
var import_cjs = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_index.require_cjs());
var _ref;
var DidCommMediationRecord = class DidCommMediationRecord extends __credo_ts_core.BaseRecord {
	constructor(props) {
		super();
		this.type = DidCommMediationRecord.type;
		this.allowCache = true;
		if (props) {
			this.id = props.id ?? __credo_ts_core.utils.uuid();
			this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
			this.connectionId = props.connectionId;
			this.threadId = props.threadId;
			this.recipientKeys = props.recipientKeys || [];
			this.routingKeys = props.routingKeys || [];
			this.state = props.state;
			this.role = props.role;
			this.endpoint = props.endpoint ?? void 0;
			this.pickupStrategy = props.pickupStrategy;
			this._tags = props.tags ?? {};
		}
	}
	getTags() {
		return {
			...this._tags,
			state: this.state,
			role: this.role,
			connectionId: this.connectionId,
			threadId: this.threadId,
			recipientKeys: this.recipientKeys
		};
	}
	addRecipientKey(recipientKey) {
		this.recipientKeys.push(recipientKey);
	}
	removeRecipientKey(recipientKey) {
		const index = this.recipientKeys.indexOf(recipientKey, 0);
		if (index > -1) {
			this.recipientKeys.splice(index, 1);
			return true;
		}
		return false;
	}
	get isReady() {
		return this.state === require_DidCommMediationState.DidCommMediationState.Granted;
	}
	assertReady() {
		if (!this.isReady) throw new __credo_ts_core.CredoError(`Mediation record is not ready to be used. Expected ${require_DidCommMediationState.DidCommMediationState.Granted}, found invalid state ${this.state}`);
	}
	assertState(expectedStates) {
		if (!Array.isArray(expectedStates)) expectedStates = [expectedStates];
		if (!expectedStates.includes(this.state)) throw new __credo_ts_core.CredoError(`Mediation record is in invalid state ${this.state}. Valid states are: ${expectedStates.join(", ")}.`);
	}
	assertRole(expectedRole) {
		if (this.role !== expectedRole) throw new __credo_ts_core.CredoError(`Mediation record has invalid role ${this.role}. Expected role ${expectedRole}.`);
	}
};
DidCommMediationRecord.type = "MediationRecord";
DidCommMediationRecord.allowCache = true;
require_decorate.__decorate([(0, import_cjs.Transform)(({ value }) => {
	if (value === "Explicit") return require_DidCommMediatorPickupStrategy.DidCommMediatorPickupStrategy.PickUpV1;
	return value;
}), require_decorateMetadata.__decorateMetadata("design:type", typeof (_ref = typeof require_DidCommMediatorPickupStrategy.DidCommMediatorPickupStrategy !== "undefined" && require_DidCommMediatorPickupStrategy.DidCommMediatorPickupStrategy) === "function" ? _ref : Object)], DidCommMediationRecord.prototype, "pickupStrategy", void 0);

//#endregion
exports.DidCommMediationRecord = DidCommMediationRecord;