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

#include "Common"
#include <osgEarth/Sky>

namespace osgEarth { namespace SilverLining
{
    /**
     * Options for creating a SilverLining environment node
     */
    class /*header only*/ SilverLiningOptions : public osgEarth::SkyOptions
    {
    public:
        SilverLiningOptions(const osgEarth::SkyOptions& options =osgEarth::SkyOptions()) :
          osgEarth::SkyOptions(options),
          _drawClouds(false),
          _cloudsMaxAltitude(20000)
        {
            setDriver( "silverlining" );
            fromConfig( _conf );
        }
        virtual ~SilverLiningOptions() { }

    public: // properties

        /* User name for license activation */
        optional<std::string>& user() { return _user; }
        const optional<std::string>& user() const { return _user; }

        /* License code string */
        optional<std::string>& licenseCode() { return _licenseCode; }
        const optional<std::string>& licenseCode() const { return _licenseCode; }

        /* SilverLining resource path */
        optional<std::string>& resourcePath() { return _resourcePath; }
        const optional<std::string>& resourcePath() const { return _resourcePath; }

        /* Whether to draw clouds */
        optional<bool>& drawClouds() { return _drawClouds; }
        const optional<bool>& drawClouds() const { return _drawClouds; }

		/* Max altitude at which to draw/update clouds */
		optional<double>& cloudsMaxAltitude() { return _cloudsMaxAltitude; }
		const optional<double>& cloudsMaxAltitude() const { return _cloudsMaxAltitude; }

    public:
        osgEarth::Config getConfig() const {
            osgEarth::Config conf = osgEarth::SkyOptions::getConfig();
            conf.set("user", _user);
            conf.set("license_code", _licenseCode);
            conf.set("resource_path", _resourcePath);
            conf.set("clouds", _drawClouds);
			conf.set("clouds_max_altitude", _cloudsMaxAltitude);
            return conf;
        }

    protected:
        void mergeConfig( const osgEarth::Config& conf ) {
            osgEarth::SkyOptions::mergeConfig( conf );
            fromConfig(conf);
        }

    private:
        void fromConfig( const osgEarth::Config& conf ) {
            conf.get("user", _user);
            conf.get("license_code", _licenseCode);
            conf.get("resource_path", _resourcePath);
            conf.get("clouds", _drawClouds);
			conf.get("clouds_max_altitude", _cloudsMaxAltitude);
        }

        osgEarth::optional<std::string> _user;
        osgEarth::optional<std::string> _licenseCode;
        osgEarth::optional<std::string> _resourcePath;
        osgEarth::optional<bool>        _drawClouds;
		osgEarth::optional<double>      _cloudsMaxAltitude;
		int                             _lastCullFrameNumber;
    };

} } // namespace osgEarth::SilverLiningPlugin

#endif // OSGEARTH_DRIVER_SILVERLINING_OPTIONS

