import ContentAttachmentPayload from "./ContentAttachmentPayload.js";
import EdgeRecord from "./EdgeRecord.js";
import NodeRecord from "./NodeRecord.js";
import WarpError from "../errors/WarpError.js";
/** Runtime-backed content attachment bound to a node or edge owner. */
export default class ContentAttachmentRecord {
    owner;
    payload;
    constructor(fields) {
        const checkedFields = requireFields(fields);
        this.owner = requireOwner(checkedFields.owner);
        this.payload = requirePayload(checkedFields.payload);
        Object.freeze(this);
    }
    /** Returns true when this content is owned by a node record. */
    isNodeContent() {
        return this.owner instanceof NodeRecord;
    }
    /** Returns true when this content is owned by an edge record. */
    isEdgeContent() {
        return this.owner instanceof EdgeRecord;
    }
}
/** Validates the content attachment record constructor envelope. */
function requireFields(fields) {
    if (fields === null || fields === undefined) {
        throw new WarpError('ContentAttachmentRecord fields must be provided', 'E_VALIDATION');
    }
    return fields;
}
/** Requires a runtime-backed content owner. */
function requireOwner(value) {
    if (value instanceof NodeRecord || value instanceof EdgeRecord) {
        return value;
    }
    throw new WarpError('ContentAttachmentRecord owner must be a NodeRecord or EdgeRecord', 'E_VALIDATION');
}
/** Requires a runtime-backed content payload. */
function requirePayload(value) {
    if (!(value instanceof ContentAttachmentPayload)) {
        throw new WarpError('ContentAttachmentRecord payload must be a ContentAttachmentPayload', 'E_VALIDATION');
    }
    return value;
}
