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

#include "Common"
#include "SilverLiningOptions"
#include "SilverLiningCallback"
#include "SilverLiningAPIWrapper"
#include <osgEarth/PhongLightingEffect>
#include <osg/Light>
#include <osg/LightSource>
#include <osg/Geode>

namespace osgEarth { namespace SilverLining
{
    class SilverLiningContext;
    class SilverLiningNode;

    /**
     * Node that roots the silverlining adapter.
     */
    class SilverLiningContextNode : public osg::Group
    {
    public:
        SilverLiningContextNode(
            SilverLiningNode*          node,
            osg::Camera*               camera,
            osg::Light*                light,
            const SilverLiningOptions& options,
            Callback*                  callback =0L);

    public: 
        void attach(osg::View* view, int lightNum);

        // callbacks from SilverLiningNode.
        void onSetDateTime();
        //get target camera
        osg::Camera* getTargetCamera() const {return _camera;}
        osg::ref_ptr<osg::Geode> getSLGeode() {return _geode;}
        SilverLiningContext* getSLContext() {return _SL.get();}

        osg::StateSet* getCloudsStateSet() const { return _cloudsDrawable.valid() ? _cloudsDrawable->getStateSet() : 0L; }
        osg::StateSet* getSkyStateSet() const { return _skyDrawable.valid() ? _skyDrawable->getStateSet() : 0L; }

    public: // osg::Node

        void traverse(osg::NodeVisitor&);

    protected:
        virtual ~SilverLiningContextNode();

        osg::ref_ptr<SilverLiningContext> _SL;
        osg::ref_ptr<osg::Geode> _geode;
        osg::ref_ptr<osg::Drawable> _skyDrawable;
        osg::ref_ptr<osg::Drawable> _cloudsDrawable;
        SilverLiningNode* _silverLiningNode;
        double _lastAltitude;
        const SilverLiningOptions _options;
        osg::Camera* _camera;
    };

} } // namespace osgEarth::SilverLining