import ShadowTrieORSetError from "../../errors/ShadowTrieORSetError.js";
import TrieCursor from "../trie/TrieCursor.js";
import TrieFlusher from "../trie/TrieFlusher.js";
/**
 * Async storage-backed ORSet engine built on the trie substrate.
 *
 * This is an internal engine, not the domain-facing session seam.
 * `StateSession` will own lifetime and compose one or more of these
 * engines later.
 */
export default class ShadowTrieORSet {
    #cursor;
    #flusher;
    constructor(init) {
        if (!(init.cursor instanceof TrieCursor)) {
            throw new ShadowTrieORSetError("ShadowTrieORSet requires a TrieCursor", { context: { field: "cursor" } });
        }
        if (!(init.flusher instanceof TrieFlusher)) {
            throw new ShadowTrieORSetError("ShadowTrieORSet requires a TrieFlusher", { context: { field: "flusher" } });
        }
        this.#cursor = init.cursor;
        this.#flusher = init.flusher;
        Object.freeze(this);
    }
    async contains(element) {
        return await this.#cursor.contains(element);
    }
    async getDots(element) {
        return await this.#cursor.getDots(element);
    }
    async getElementState(element) {
        return await this.#cursor.getElementState(element);
    }
    async add(element, dot) {
        await this.#cursor.add(element, dot);
    }
    async remove(observedDots) {
        await this.#cursor.remove(observedDots);
    }
    async compact(includedVV) {
        await this.#cursor.compact(includedVV);
    }
    async *scan() {
        yield* this.#cursor.scan();
    }
    async *scanElementStates() {
        yield* this.#cursor.scanElementStates();
    }
    async flush() {
        return await this.#flusher.flush(this.#cursor.snapshot());
    }
}
