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_DidCommAttachment = require('../../../decorators/attachment/DidCommAttachment.js');
const require_DidCommRevocationNotification = require('../models/DidCommRevocationNotification.js');
const require_DidCommCredentialPreviewAttribute = require('../models/DidCommCredentialPreviewAttribute.js');
let __credo_ts_core = require("@credo-ts/core");
__credo_ts_core = require_rolldown_runtime.__toESM(__credo_ts_core);

//#region ../didcomm/src/modules/credentials/repository/DidCommCredentialExchangeRecord.ts
var import_cjs = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_index.require_cjs());
var _ref;
var DidCommCredentialExchangeRecord = class DidCommCredentialExchangeRecord extends __credo_ts_core.BaseRecord {
	constructor(props) {
		super();
		this.credentials = [];
		this.type = DidCommCredentialExchangeRecord.type;
		if (props) {
			this.id = props.id ?? __credo_ts_core.utils.uuid();
			this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
			this.state = props.state;
			this.role = props.role;
			this.connectionId = props.connectionId;
			this.threadId = props.threadId;
			this.parentThreadId = props.parentThreadId;
			this.protocolVersion = props.protocolVersion;
			this._tags = props.tags ?? {};
			this.credentialAttributes = props.credentialAttributes;
			this.autoAcceptCredential = props.autoAcceptCredential;
			this.linkedAttachments = props.linkedAttachments;
			this.revocationNotification = props.revocationNotification;
			this.errorMessage = props.errorMessage;
			this.credentials = props.credentials || [];
		}
	}
	getTags() {
		const ids = this.credentials.map((c) => c.credentialRecordId);
		return {
			...this._tags,
			threadId: this.threadId,
			parentThreadId: this.parentThreadId,
			connectionId: this.connectionId,
			state: this.state,
			role: this.role,
			credentialIds: ids
		};
	}
	assertProtocolVersion(version) {
		if (this.protocolVersion !== version) throw new __credo_ts_core.CredoError(`Credential record has invalid protocol version ${this.protocolVersion}. Expected version ${version}`);
	}
	assertState(expectedStates) {
		if (!Array.isArray(expectedStates)) expectedStates = [expectedStates];
		if (!expectedStates.includes(this.state)) throw new __credo_ts_core.CredoError(`Credential record is in invalid state ${this.state}. Valid states are: ${expectedStates.join(", ")}.`);
	}
	assertConnection(currentConnectionId) {
		if (!this.connectionId) throw new __credo_ts_core.CredoError("Credential record is not associated with any connection. This is often the case with connection-less credential exchange");
		if (this.connectionId !== currentConnectionId) throw new __credo_ts_core.CredoError(`Credential record is associated with connection '${this.connectionId}'. Current connection is '${currentConnectionId}'`);
	}
};
DidCommCredentialExchangeRecord.type = "CredentialRecord";
require_decorate.__decorate([(0, import_cjs.Type)(() => require_DidCommRevocationNotification.DidCommRevocationNotification), require_decorateMetadata.__decorateMetadata("design:type", typeof (_ref = typeof require_DidCommRevocationNotification.DidCommRevocationNotification !== "undefined" && require_DidCommRevocationNotification.DidCommRevocationNotification) === "function" ? _ref : Object)], DidCommCredentialExchangeRecord.prototype, "revocationNotification", void 0);
require_decorate.__decorate([(0, import_cjs.Type)(() => require_DidCommCredentialPreviewAttribute.DidCommCredentialPreviewAttribute), require_decorateMetadata.__decorateMetadata("design:type", Array)], DidCommCredentialExchangeRecord.prototype, "credentialAttributes", void 0);
require_decorate.__decorate([(0, import_cjs.Type)(() => require_DidCommAttachment.DidCommAttachment), require_decorateMetadata.__decorateMetadata("design:type", Array)], DidCommCredentialExchangeRecord.prototype, "linkedAttachments", void 0);

//#endregion
exports.DidCommCredentialExchangeRecord = DidCommCredentialExchangeRecord;