/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { OffsetCursor } from "@vertexvis/scene-tree-protos/core/protos/paging_pb";
import { Uuid } from "@vertexvis/scene-tree-protos/core/protos/uuid_pb";
import { IndexingStatus, ListChange, Node, TreeChangeType, } from "@vertexvis/scene-tree-protos/scenetree/protos/domain_pb";
import { FilterResponse, GetTreeResponse, SubscribeResponse, } from "@vertexvis/scene-tree-protos/scenetree/protos/scene_tree_api_pb";
import { EventDispatcher } from "@vertexvis/utils";
import { random } from "./random";
export class ResponseStreamMock {
    constructor() {
        this.onData = new EventDispatcher();
        this.onStatus = new EventDispatcher();
        this.onEnd = new EventDispatcher();
    }
    cancel() {
        // no op
    }
    on(type, handler) {
        if (type === 'data') {
            this.onData.on(handler);
        }
        else if (type === 'end') {
            this.onEnd.on(handler);
        }
        else {
            this.onStatus.on(handler);
        }
        return this;
    }
    invokeOnData(msg) {
        this.onData.emit(msg);
    }
    invokeOnEnd(status) {
        this.onEnd.emit(status);
    }
    invokeOnStatus(status) {
        this.onStatus.emit(status);
    }
}
export function createGetTreeResponse(itemCount, totalCount, transform) {
    const nodes = Array.from({ length: itemCount }).map((_, i) => {
        const id = new Uuid();
        id.setHex(random.guid());
        const node = new Node();
        node.setId(id);
        node.setDepth(0);
        node.setExpanded(false);
        node.setIsLeaf(false);
        node.setName(random.string());
        node.setSelected(false);
        node.setVisible(false);
        transform === null || transform === void 0 ? void 0 : transform(node);
        return node;
    });
    const cursor = new OffsetCursor();
    if (totalCount != null) {
        cursor.setTotal(totalCount);
    }
    const res = new GetTreeResponse();
    res.setItemsList(nodes);
    res.setCursor(cursor);
    return res;
}
export function createFilterTreeResponse(resultCount, partialResults = false) {
    const res = new FilterResponse();
    res.setNumberOfResults(resultCount);
    res.setIndexingStatus(partialResults
        ? IndexingStatus.INDEXING_STATUS_INDEXING
        : IndexingStatus.INDEXING_STATUS_READY);
    return res;
}
export function createSubscribeResponse(change) {
    const res = new SubscribeResponse();
    res.setChange(change);
    return res;
}
export function createListChange(start) {
    const change = new TreeChangeType();
    const listChange = new ListChange();
    listChange.setStart(start);
    change.setListChange(listChange);
    return change;
}
//# sourceMappingURL=sceneTree.js.map
