#pragma once
#include <osgEarthProcedural/Export>
#include <osgEarth/TileLayer>
#include <osgEarth/FeatureSource>
#include <osgEarth/LayerReference>
#include <osgEarth/MaterialLoader>
#include <osgEarth/Units>

namespace osgEarth
{
    namespace Util
    {
        class SimplePager;
    }

    namespace Procedural
    {
        struct OSGEARTHPROCEDURAL_EXPORT RoadLayerArt
        {
            RoadLayerArt(const Config& conf = {});
            Config getConfig() const;

            OE_OPTION(PBRMaterial, substrateMaterial, {});
            OE_OPTION(Distance, substrateBuffer, Distance(1.0, Units::METERS));
            OE_OPTION(PBRMaterial, lanesMaterial, {});
            OE_OPTION(PBRMaterial, crossingsMaterial, {});
            OE_OPTION(PBRMaterial, intersectionsMaterial, {});
        };

        class OSGEARTHPROCEDURAL_EXPORT RoadLayer : public TileLayer
        {
        public:
            class OSGEARTHPROCEDURAL_EXPORT Options : public TileLayer::Options
            {
                META_LayerOptions(osgEarthProcedural, Options, TileLayer::Options);
                OE_OPTION_LAYER(FeatureSource, features);
                OE_OPTION(RoadLayerArt, art);
                OE_OPTION(bool, useConstraints, false);
                OE_OPTION(unsigned, substrateMinLevel, 18u);
                OE_OPTION(unsigned, constraintsMinLevel, 17u);
                void fromConfig(const Config& conf);
                Config getConfig() const override;
            };

            META_Layer(osgEarthProcedural, RoadLayer, Options, TileLayer, roads);

        public: // Layer
            void init() override;
            Status openImplementation() override;

        private:
            osg::ref_ptr<VisibleLayer> _substrateLayer;
            osg::ref_ptr<VisibleLayer> _decalsLayer;
            osg::ref_ptr<VisibleLayer> _constraintsLayer;
        };
    }
}

OSGEARTH_SPECIALIZE_CONFIG(osgEarth::Procedural::RoadLayerArt);