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 { DidCommAttachment } from "../../../decorators/attachment/DidCommAttachment.mjs";
import { DidCommRevocationNotification } from "../models/DidCommRevocationNotification.mjs";
import { DidCommCredentialPreviewAttribute } from "../models/DidCommCredentialPreviewAttribute.mjs";
import { BaseRecord, CredoError, utils } from "@credo-ts/core";
import { Type } from "class-transformer";

//#region ../didcomm/src/modules/credentials/repository/DidCommCredentialExchangeRecord.ts
var _ref;
var DidCommCredentialExchangeRecord = class DidCommCredentialExchangeRecord extends BaseRecord {
	constructor(props) {
		super();
		this.credentials = [];
		this.type = DidCommCredentialExchangeRecord.type;
		if (props) {
			this.id = props.id ?? 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 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 CredoError(`Credential record is in invalid state ${this.state}. Valid states are: ${expectedStates.join(", ")}.`);
	}
	assertConnection(currentConnectionId) {
		if (!this.connectionId) throw new 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 CredoError(`Credential record is associated with connection '${this.connectionId}'. Current connection is '${currentConnectionId}'`);
	}
};
DidCommCredentialExchangeRecord.type = "CredentialRecord";
__decorate([Type(() => DidCommRevocationNotification), __decorateMetadata("design:type", typeof (_ref = typeof DidCommRevocationNotification !== "undefined" && DidCommRevocationNotification) === "function" ? _ref : Object)], DidCommCredentialExchangeRecord.prototype, "revocationNotification", void 0);
__decorate([Type(() => DidCommCredentialPreviewAttribute), __decorateMetadata("design:type", Array)], DidCommCredentialExchangeRecord.prototype, "credentialAttributes", void 0);
__decorate([Type(() => DidCommAttachment), __decorateMetadata("design:type", Array)], DidCommCredentialExchangeRecord.prototype, "linkedAttachments", void 0);

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