/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Geometry
 */
import { assert, CompressedId64Set, DbOpcode } from "@itwin/core-bentley";
import { Range3d } from "@itwin/core-geometry";
/** Represents a change to the geometry of a [GeometricElement]($backend), as exposed by [[ModelGeometryChanges.elements]].
 * @public
 */
export var ElementGeometryChange;
(function (ElementGeometryChange) {
    function* extantIterator(props, type) {
        let index = 0;
        const ids = CompressedId64Set.iterable(props.ids);
        for (const id of ids) {
            assert(undefined !== props.ranges[index]);
            const range = Range3d.fromJSON(props.ranges[index]);
            index++;
            yield { type, id, range };
        }
    }
    function extantIterable(props, type) {
        return { [Symbol.iterator]: () => extantIterator(props, type) };
    }
    /** Obtain an iterator over the geometry changes for a single [GeometricModel]($backend). A given element will appear at most once. */
    function* iterator(modelChanges) {
        if (modelChanges.inserted)
            yield* extantIterable(modelChanges.inserted, DbOpcode.Insert);
        if (modelChanges.updated)
            yield* extantIterable(modelChanges.updated, DbOpcode.Update);
        if (modelChanges.deleted)
            for (const id of CompressedId64Set.iterable(modelChanges.deleted))
                yield { type: DbOpcode.Delete, id };
    }
    ElementGeometryChange.iterator = iterator;
    /** Obtain an iterable over the geometry changes for a single [GeometricModel]($backend). A given element will appear at most once. */
    function iterable(modelChanges) {
        return { [Symbol.iterator]: () => iterator(modelChanges) };
    }
    ElementGeometryChange.iterable = iterable;
})(ElementGeometryChange || (ElementGeometryChange = {}));
/** Represents geometric changes to a set of [GeometricElement]($backend)s belonging to a single [GeometricModel]($backend).
 * @see [GraphicalEditingScope]($frontend) to monitor these changes.
 * @public
 */
export var ModelGeometryChanges;
(function (ModelGeometryChanges) {
    /** Obtain an iterator over the geometry changes for a set of models. A given model will appear at most once. */
    function* iterator(modelChanges) {
        for (const props of modelChanges)
            yield fromJSON(props);
    }
    ModelGeometryChanges.iterator = iterator;
    /** Obtain an iterable over the geometry changes for a set of models. A given model will appear at most once. */
    function iterable(modelChanges) {
        return { [Symbol.iterator]: () => iterator(modelChanges) };
    }
    ModelGeometryChanges.iterable = iterable;
    /** Instantiate from wire format. */
    function fromJSON(props) {
        return {
            id: props.id,
            geometryGuid: props.guid,
            range: Range3d.fromJSON(props.range),
            elements: ElementGeometryChange.iterable(props),
        };
    }
    ModelGeometryChanges.fromJSON = fromJSON;
    /** Obtain the ModelGeometryChanges for the specified model Id. */
    function findByModelId(changes, modelId) {
        for (const change of changes)
            if (change.id === modelId)
                return change;
        return undefined;
    }
    ModelGeometryChanges.findByModelId = findByModelId;
})(ModelGeometryChanges || (ModelGeometryChanges = {}));
//# sourceMappingURL=ModelGeometryChanges.js.map