/**
 * Component representing logical attachment to another entity, when the parent disappears - so does the child
 *
 * @author Alex Goldring
 * @copyright Company Named Limited (c) 2026
 */
export class ParentEntity {
    /**
     * * @constructor
     */
    constructor() {
        /**
         * Entity representing logical parent.
         * Must not be mutated (changed) while the component is attached to a dataset
         * @type {number}
         */
        this.entity = -1;
    }

    /**
     *
     * @param {number} entity
     * @returns {ParentEntity}
     */
    static from(entity) {
        const r = new ParentEntity();

        r.entity = entity;

        return r;
    }

    toJSON() {
        return {
            entity: this.entity,
        };
    }

    fromJSON({ entity }) {
        this.entity = entity;
    }
}

/**
 * @readonly
 * @type {string}
 */
ParentEntity.typeName = "ParentEntity";

/**
 * Entity IDs are transient, serialization is not applicable.
 * @type {boolean}
 */
ParentEntity.serializable = false;
