/* osgEarth
* Copyright 2025 Pelican Mapping
* MIT License
*/
#ifndef OSGEARTH_SPLAT_GROUNDCOVER_FEATURESOURCE
#define OSGEARTH_SPLAT_GROUNDCOVER_FEATURESOURCE 1

#include "Export"
#include "GroundCoverLayer"
#include "GroundCoverFeatureGenerator"
#include <osgEarth/FeatureSource>

using namespace osgEarth;

namespace osgEarth { namespace Splat
{
    /**
     * Creates features representing the location and configuration
     * of GroundCover instances.
     */
    class OSGEARTHSPLAT_EXPORT GroundCoverFeatureSource :
        public FeatureSource
    {
    public: // serialization
        class OSGEARTHSPLAT_EXPORT Options : public FeatureSource::Options
        {
        public:
            META_LayerOptions(osgEarth, Options, FeatureSource::Options);
            OE_OPTION_LAYER(GroundCoverLayer, groundCoverLayer);
            virtual Config getConfig() const;
        private:
            void fromConfig(const Config& conf);
        };

    public:
        META_Layer(osgEarth, GroundCoverFeatureSource, Options, FeatureSource, GroundCoverFeatures);

        //! GroundCoverLayer from which to generate feature data
        void setGroundCoverLayer(GroundCoverLayer* layer);
        GroundCoverLayer* getGroundCoverLayer() const;

    public: // FeatureSource

        FeatureCursor* createFeatureCursorImplementation(const Query& query, ProgressCallback* progress) const;

    protected: // Layer

        void init() override;

        Status openImplementation() override;

        Status closeImplementation() override;

        void addedToMap(const Map*) override;

        void removedFromMap(const Map*) override;
        
    private:
        GroundCoverFeatureGenerator _gen;
    };

} } // namespace osgEarth::Splat

#endif // OSGEARTH_SPLAT_GROUNDCOVER_FEATURESOURCE
