import ContentAttachmentMime from "./ContentAttachmentMime.js";
import ContentAttachmentOid from "./ContentAttachmentOid.js";
import ContentAttachmentSize from "./ContentAttachmentSize.js";
import WarpError from "../errors/WarpError.js";
/** Runtime-backed content attachment payload metadata. */
export default class ContentAttachmentPayload {
    oid;
    mime;
    size;
    constructor(fields) {
        const checkedFields = requireFields(fields);
        this.oid = requireOid(checkedFields.oid);
        this.mime = requireMime(checkedFields.mime);
        this.size = requireSize(checkedFields.size);
        Object.freeze(this);
    }
    /** Returns true when a MIME hint is present. */
    hasMime() {
        return this.mime instanceof ContentAttachmentMime;
    }
    /** Returns true when a byte length is present. */
    hasSize() {
        return this.size instanceof ContentAttachmentSize;
    }
}
/** Validates the content payload constructor envelope. */
function requireFields(fields) {
    if (fields === null || fields === undefined) {
        throw new WarpError('ContentAttachmentPayload fields must be provided', 'E_VALIDATION');
    }
    return fields;
}
/** Requires a runtime-backed content storage reference. */
function requireOid(value) {
    if (!(value instanceof ContentAttachmentOid)) {
        throw new WarpError('ContentAttachmentPayload oid must be a ContentAttachmentOid', 'E_VALIDATION');
    }
    return value;
}
/** Requires absent metadata or a runtime-backed MIME hint. */
function requireMime(value) {
    if (value === null || value instanceof ContentAttachmentMime) {
        return value;
    }
    throw new WarpError('ContentAttachmentPayload mime must be null or a ContentAttachmentMime', 'E_VALIDATION');
}
/** Requires absent metadata or a runtime-backed byte length. */
function requireSize(value) {
    if (value === null || value instanceof ContentAttachmentSize) {
        return value;
    }
    throw new WarpError('ContentAttachmentPayload size must be null or a ContentAttachmentSize', 'E_VALIDATION');
}
