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_DidCommDidExchangeState = require('../models/DidCommDidExchangeState.js');
const require_DidCommConnectionState = require('../models/DidCommConnectionState.js');
const require_DidCommDidExchangeRole = require('../models/DidCommDidExchangeRole.js');
const require_DidCommHandshakeProtocol = require('../models/DidCommHandshakeProtocol.js');
require('../models/index.js');
let __credo_ts_core = require("@credo-ts/core");
__credo_ts_core = require_rolldown_runtime.__toESM(__credo_ts_core);

//#region ../didcomm/src/modules/connections/repository/DidCommConnectionRecord.ts
var import_cjs = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_index.require_cjs());
var _ref;
var DidCommConnectionRecord = class DidCommConnectionRecord extends __credo_ts_core.BaseRecord {
	constructor(props) {
		super();
		this.connectionTypes = [];
		this.previousDids = [];
		this.previousTheirDids = [];
		this.type = DidCommConnectionRecord.type;
		this.allowCache = DidCommConnectionRecord.allowCache;
		if (props) {
			this.id = props.id ?? __credo_ts_core.utils.uuid();
			this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
			this.did = props.did;
			this.invitationDid = props.invitationDid;
			this.theirDid = props.theirDid;
			this.theirLabel = props.theirLabel;
			this.state = props.state;
			this.role = props.role;
			this.alias = props.alias;
			this.autoAcceptConnection = props.autoAcceptConnection;
			this._tags = props.tags ?? {};
			this.threadId = props.threadId;
			this.imageUrl = props.imageUrl;
			this.mediatorId = props.mediatorId;
			this.errorMessage = props.errorMessage;
			this.protocol = props.protocol;
			this.outOfBandId = props.outOfBandId;
			this.connectionTypes = props.connectionTypes ?? [];
			this.previousDids = props.previousDids ?? [];
			this.previousTheirDids = props.previousTheirDids ?? [];
		}
	}
	getTags() {
		return {
			...this._tags,
			state: this.state,
			role: this.role,
			threadId: this.threadId,
			mediatorId: this.mediatorId,
			did: this.did,
			theirDid: this.theirDid,
			outOfBandId: this.outOfBandId,
			invitationDid: this.invitationDid,
			connectionTypes: this.connectionTypes,
			previousDids: this.previousDids,
			previousTheirDids: this.previousTheirDids
		};
	}
	get isRequester() {
		return this.role === require_DidCommDidExchangeRole.DidCommDidExchangeRole.Requester;
	}
	get rfc0160State() {
		return require_DidCommConnectionState.rfc0160StateFromDidExchangeState(this.state);
	}
	get isReady() {
		return this.state && [require_DidCommDidExchangeState.DidCommDidExchangeState.Completed, require_DidCommDidExchangeState.DidCommDidExchangeState.ResponseSent].includes(this.state);
	}
	assertReady() {
		if (!this.isReady) throw new __credo_ts_core.CredoError(`Connection record is not ready to be used. Expected ${require_DidCommDidExchangeState.DidCommDidExchangeState.ResponseSent}, ${require_DidCommDidExchangeState.DidCommDidExchangeState.ResponseReceived} or ${require_DidCommDidExchangeState.DidCommDidExchangeState.Completed}, found invalid state ${this.state}`);
	}
	assertState(expectedStates) {
		if (!Array.isArray(expectedStates)) expectedStates = [expectedStates];
		if (!expectedStates.includes(this.state)) throw new __credo_ts_core.CredoError(`Connection record is in invalid state ${this.state}. Valid states are: ${expectedStates.join(", ")}.`);
	}
	assertRole(expectedRole) {
		if (this.role !== expectedRole) throw new __credo_ts_core.CredoError(`Connection record has invalid role ${this.role}. Expected role ${expectedRole}.`);
	}
};
DidCommConnectionRecord.type = "ConnectionRecord";
DidCommConnectionRecord.allowCache = true;
require_decorate.__decorate([(0, import_cjs.Transform)(({ value }) => {
	if (!value || typeof value !== "string" || value.endsWith(".x")) return value;
	return `${value.split(".").slice(0, -1).join(".")}.x`;
}, { toClassOnly: true }), require_decorateMetadata.__decorateMetadata("design:type", typeof (_ref = typeof require_DidCommHandshakeProtocol.DidCommHandshakeProtocol !== "undefined" && require_DidCommHandshakeProtocol.DidCommHandshakeProtocol) === "function" ? _ref : Object)], DidCommConnectionRecord.prototype, "protocol", void 0);

//#endregion
exports.DidCommConnectionRecord = DidCommConnectionRecord;