import ORSetElementStateError from "../errors/ORSetElementStateError.js";
/**
 * Runtime-backed OR-Set element state.
 *
 * Carries the live and tombstoned dots for one element without
 * leaking trie leaf transport shapes upward.
 */
export default class ORSetElementState {
    #element;
    #dots;
    #tombstonedDots;
    constructor(fields) {
        validateElement(fields.element);
        validateDots("dots", fields.dots);
        validateDots("tombstonedDots", fields.tombstonedDots);
        this.#element = fields.element;
        this.#dots = new Set(fields.dots);
        this.#tombstonedDots = new Set(fields.tombstonedDots);
        Object.freeze(this);
    }
    get element() {
        return this.#element;
    }
    get dots() {
        return new Set(this.#dots);
    }
    get tombstonedDots() {
        return new Set(this.#tombstonedDots);
    }
    hasLiveDots() {
        return this.#dots.size > 0;
    }
}
function validateElement(element) {
    if (typeof element !== "string" || element.length === 0) {
        throw new ORSetElementStateError(`ORSetElementState requires a non-empty element string; received ${String(element)}`, { context: { field: "element", element } });
    }
}
function validateDots(field, dots) {
    if (!(dots instanceof Set)) {
        throw new ORSetElementStateError(`ORSetElementState requires ${field} to be a Set<string>`, { context: { field } });
    }
    for (const dot of dots) {
        if (typeof dot !== "string") {
            throw new ORSetElementStateError(`ORSetElementState requires ${field} to contain only strings`, { context: { field, dot: String(dot) } });
        }
    }
}
