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 { CredoError, JsonEncoder, utils } from "@credo-ts/core";
import { Expose, Type } from "class-transformer";
import { IsDate, IsHash, IsInstance, IsInt, IsMimeType, IsOptional, IsString, ValidateNested } from "class-validator";

//#region ../didcomm/src/decorators/attachment/DidCommAttachment.ts
var _ref, _ref2;
/**
* A JSON object that gives access to the actual content of the attachment
*/
var DidCommAttachmentData = class {
	constructor(options) {
		if (options) {
			this.base64 = options.base64;
			this.json = options.json;
			this.links = options.links;
			this.jws = options.jws;
			this.sha256 = options.sha256;
		}
	}
};
__decorate([
	IsOptional(),
	IsString(),
	__decorateMetadata("design:type", String)
], DidCommAttachmentData.prototype, "base64", void 0);
__decorate([IsOptional(), __decorateMetadata("design:type", Object)], DidCommAttachmentData.prototype, "json", void 0);
__decorate([
	IsOptional(),
	IsString({ each: true }),
	__decorateMetadata("design:type", Array)
], DidCommAttachmentData.prototype, "links", void 0);
__decorate([IsOptional(), __decorateMetadata("design:type", Object)], DidCommAttachmentData.prototype, "jws", void 0);
__decorate([
	IsOptional(),
	IsHash("sha256"),
	__decorateMetadata("design:type", String)
], DidCommAttachmentData.prototype, "sha256", void 0);
/**
* Represents DIDComm attachment
* https://github.com/hyperledger/aries-rfcs/blob/master/concepts/0017-attachments/README.md
*/
var DidCommAttachment = class {
	constructor(options) {
		if (options) {
			this.id = options.id ?? utils.uuid();
			this.description = options.description;
			this.filename = options.filename;
			this.mimeType = options.mimeType;
			this.lastmodTime = options.lastmodTime;
			this.byteCount = options.byteCount;
			this.data = new DidCommAttachmentData(options.data);
		}
	}
	getDataAsJson() {
		if (typeof this.data.base64 === "string") return JsonEncoder.fromBase64(this.data.base64);
		if (this.data.json) return this.data.json;
		throw new CredoError("No attachment data found in `json` or `base64` data fields.");
	}
	addJws(jws) {
		const { payload,...detachedJws } = jws;
		if (!this.data.jws) this.data.jws = detachedJws;
		else if ("signatures" in this.data.jws) this.data.jws.signatures.push(detachedJws);
		else this.data.jws = { signatures: [this.data.jws, detachedJws] };
	}
};
__decorate([Expose({ name: "@id" }), __decorateMetadata("design:type", String)], DidCommAttachment.prototype, "id", void 0);
__decorate([
	IsOptional(),
	IsString(),
	__decorateMetadata("design:type", String)
], DidCommAttachment.prototype, "description", void 0);
__decorate([
	IsOptional(),
	IsString(),
	__decorateMetadata("design:type", String)
], DidCommAttachment.prototype, "filename", void 0);
__decorate([
	Expose({ name: "mime-type" }),
	IsOptional(),
	IsMimeType(),
	__decorateMetadata("design:type", String)
], DidCommAttachment.prototype, "mimeType", void 0);
__decorate([
	Expose({ name: "lastmod_time" }),
	Type(() => Date),
	IsOptional(),
	IsDate(),
	__decorateMetadata("design:type", typeof (_ref = typeof Date !== "undefined" && Date) === "function" ? _ref : Object)
], DidCommAttachment.prototype, "lastmodTime", void 0);
__decorate([
	Expose({ name: "byte_count" }),
	IsOptional(),
	IsInt(),
	__decorateMetadata("design:type", Number)
], DidCommAttachment.prototype, "byteCount", void 0);
__decorate([
	Type(() => DidCommAttachmentData),
	ValidateNested(),
	IsInstance(DidCommAttachmentData),
	__decorateMetadata("design:type", typeof (_ref2 = typeof DidCommAttachmentData !== "undefined" && DidCommAttachmentData) === "function" ? _ref2 : Object)
], DidCommAttachment.prototype, "data", void 0);

//#endregion
export { DidCommAttachment, DidCommAttachmentData };
//# sourceMappingURL=DidCommAttachment.mjs.map