/* osgEarth
 * Copyright 2025 Pelican Mapping
 * MIT License
 */

#ifndef OSGEARTH_MAP_MODEL_CHANGE_H
#define OSGEARTH_MAP_MODEL_CHANGE_H 1

#include <osgEarth/Common>
#include <osgEarth/Revisioning>
#include <osgEarth/ImageLayer>
#include <osgEarth/ElevationLayer>
#include <osgEarth/ModelLayer>
#include <osgEarth/TerrainConstraintLayer>

namespace osgEarth
{
    /**
     * Conveys atomic change actions to the map data model.
     */
    struct MapModelChange /* no export, header-only */
    {
        enum ActionType
        {
            BEGIN_BATCH_UPDATE,         // signals the start of multiple changes
            END_BATCH_UPDATE,           // signals the end of multiple changes
            ADD_LAYER,
            REMOVE_LAYER,
            MOVE_LAYER,
            OPEN_LAYER,
            CLOSE_LAYER,
            UNSPECIFIED
        };

        MapModelChange() : _action(UNSPECIFIED), _firstIndex(0), _secondIndex(0) { }

        MapModelChange( ActionType action, Revision mapModeRev, Layer* layer =0L, int firstIndex =-1, int secondIndex =-1 )
            : _action(action), _layer(layer), _modelRevision(mapModeRev), _firstIndex(firstIndex), _secondIndex(secondIndex) { }

        const ActionType& getAction() const { return _action; }
        const Revision& getRevision() const { return _modelRevision; }
        int getFirstIndex() const { return _firstIndex; }
        int getSecondIndex() const { return _secondIndex; }
        Layer* getLayer() const { return _layer.get(); }
        ImageLayer* getImageLayer() const { return dynamic_cast<ImageLayer*>(_layer.get()); }
        ElevationLayer* getElevationLayer() const { return dynamic_cast<ElevationLayer*>(_layer.get()); }
        ModelLayer* getModelLayer() const { return dynamic_cast<ModelLayer*>(_layer.get()); }
        TerrainConstraintLayer* getConstraintLayer() const { return dynamic_cast<TerrainConstraintLayer*>(_layer.get()); }

    private:
        ActionType          _action;
        osg::ref_ptr<Layer> _layer;
        Revision            _modelRevision;
        int                 _firstIndex, _secondIndex;
    };
}

#endif // OSGEARTH_MAP_MODEL_CHANGE_H
