/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
 * Copyright 2018 Pelican Mapping
 * http://osgearth.org
 *
 * osgEarth is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
#ifndef OSGEARTH_DRIVER_SILVERLINING_OPTIONS
#define OSGEARTH_DRIVER_SILVERLINING_OPTIONS 1

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

namespace osgEarth { namespace SilverLining
{
    /**
     * Options for creating a SilverLining environment node
     */
    class /*header only*/ SilverLiningOptions : public osgEarth::Util::SkyOptions
    {
    public:
        SilverLiningOptions(const osgEarth::Util::SkyOptions& options =osgEarth::Util::SkyOptions()) :
          osgEarth::Util::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::Util::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::Util::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

