import { __decorateMetadata } from "../../../../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorateMetadata.mjs";
import { __decorate } from "../../../../../../_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.mjs";
import { DidCommMediationState } from "../models/DidCommMediationState.mjs";
import { DidCommMediatorPickupStrategy } from "../DidCommMediatorPickupStrategy.mjs";
import { BaseRecord, CredoError, utils } from "@credo-ts/core";
import { Transform } from "class-transformer";

//#region ../didcomm/src/modules/routing/repository/DidCommMediationRecord.ts
var _ref;
var DidCommMediationRecord = class DidCommMediationRecord extends BaseRecord {
	constructor(props) {
		super();
		this.type = DidCommMediationRecord.type;
		this.allowCache = true;
		if (props) {
			this.id = props.id ?? 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 === DidCommMediationState.Granted;
	}
	assertReady() {
		if (!this.isReady) throw new CredoError(`Mediation record is not ready to be used. Expected ${DidCommMediationState.Granted}, found invalid state ${this.state}`);
	}
	assertState(expectedStates) {
		if (!Array.isArray(expectedStates)) expectedStates = [expectedStates];
		if (!expectedStates.includes(this.state)) throw new CredoError(`Mediation record is in invalid state ${this.state}. Valid states are: ${expectedStates.join(", ")}.`);
	}
	assertRole(expectedRole) {
		if (this.role !== expectedRole) throw new CredoError(`Mediation record has invalid role ${this.role}. Expected role ${expectedRole}.`);
	}
};
DidCommMediationRecord.type = "MediationRecord";
DidCommMediationRecord.allowCache = true;
__decorate([Transform(({ value }) => {
	if (value === "Explicit") return DidCommMediatorPickupStrategy.PickUpV1;
	return value;
}), __decorateMetadata("design:type", typeof (_ref = typeof DidCommMediatorPickupStrategy !== "undefined" && DidCommMediatorPickupStrategy) === "function" ? _ref : Object)], DidCommMediationRecord.prototype, "pickupStrategy", void 0);

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