/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { Pager } from "@vertexvis/scene-view-protos/core/protos/paging_pb";
import { ListItemModelViewsRequest, } from "@vertexvis/scene-view-protos/sceneview/protos/scene_view_api_pb";
import { BoolValue } from "google-protobuf/google/protobuf/wrappers_pb";
import { createMetadata, requestUnary } from "../grpc";
import { toUuid2l } from "../mappers/uuid";
import { mapItemModelViewOrThrow, mapListItemModelViewsResponseOrThrow, } from "./mapper";
/**
 * The controller for managing the model views of a scene view.
 */
export class ModelViewController {
    constructor(client, stream, jwtProvider, deviceIdProvider) {
        this.client = client;
        this.stream = stream;
        this.jwtProvider = jwtProvider;
        this.deviceIdProvider = deviceIdProvider;
    }
    /**
     * Fetches a page of model views for a given item. The result includes a
     * cursor that can be used to fetch the next page of results.
     *
     * @param itemId The ID of the scene item to retrieve model views for.
     * @param options Options to configure fetching of items.
     * @returns A page of model views.
     */
    async listByItem(itemId, { hasAnnotations, cursor, size = 50 } = {}) {
        const res = await requestUnary(async (handler) => {
            const deviceId = this.deviceIdProvider();
            const meta = await createMetadata(this.jwtProvider, deviceId);
            const req = new ListItemModelViewsRequest();
            const itemId2l = toUuid2l(itemId);
            req.setItemId(itemId2l);
            if (hasAnnotations != null) {
                const hasAnnotationsVal = new BoolValue();
                hasAnnotationsVal.setValue(hasAnnotations);
                req.setHasAnnotations(hasAnnotationsVal);
            }
            const page = new Pager();
            page.setLimit(size);
            if (cursor != null) {
                page.setCursor(cursor);
            }
            req.setPage(page);
            this.client.listItemModelViews(req, meta, handler);
        });
        return mapListItemModelViewsResponseOrThrow(res.toObject());
    }
    /**
     * Loads the provided model view within the current scene view.
     *
     * @param sceneItemId The ID of the scene item this model view is being loaded for.
     * @param modelViewId The ID of the model view to load.
     */
    async load(sceneItemId, modelViewId) {
        const itemModelView = mapItemModelViewOrThrow({ modelViewId, sceneItemId });
        this.stream.updateModelView({ itemModelView }, true);
    }
    /**
     * Unloads any previously loaded model view within the current scene view,
     * then performs a `reset` on the scene to return to the initial state for
     * the scene view.
     */
    async unload() {
        await this.stream.updateModelView({}, true);
    }
}
//# sourceMappingURL=controller.js.map
