/* -*-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_TRITON_OPTIONS
#define OSGEARTH_TRITON_OPTIONS 1

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

namespace osgEarth { namespace Triton
{
    /**
     * Options for controlling the ocean surface node.
     */
    class /*header-only*/ TritonOptions : public osgEarth::Util::OceanOptions
    {
    public:
        TritonOptions(const osgEarth::Util::OceanOptions& conf = osgEarth::Util::OceanOptions()) :
            osgEarth::Util::OceanOptions( conf )
        {
            setDriver( "triton" );
            _useHeightMap.init( true );
            _heightMapSize.init( 1024 );
            _renderBinNumber.init( 12 );
            fromConfig( _conf );
        }

        virtual ~TritonOptions() { }

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

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

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

        /** Whether to pass a heightmap raster to Triton to mitigate coastline interference */
        osgEarth::optional<bool>& useHeightMap() { return _useHeightMap; }
        const osgEarth::optional<bool>& useHeightMap() const { return _useHeightMap; }

        /** Texture size to use for the height map */
        osgEarth::optional<int>& heightMapSize() { return _heightMapSize; }
        const osgEarth::optional<int>& heightMapSize() const { return _heightMapSize; }

        /** Render bin number to assign to the ocean (in DepthSortedBin) */
        optional<int>& renderBinNumber() { return _renderBinNumber; }
        const optional<int>& renderBinNumber() const { return _renderBinNumber; }

        /** Name of optional land mask layer. A land mask layer is an image layer
          * in the Map that has the alpha channel set to 1 over land and 0 over ocean.
          * This is used in addition to the height map to prevent drawing the ocean
          * over land areas.
          */
        optional<std::string>& maskLayer() { return _maskLayerName; }
        const optional<std::string>& maskLayer() const { return _maskLayerName; }

    public:
        osgEarth::Config getConfig() const {
            osgEarth::Config conf = osgEarth::Util::OceanOptions::getConfig();
            conf.set("user", _user);
            conf.set("license_code", _licenseCode);
            conf.set("resource_path", _resourcePath);
            conf.set("use_height_map", _useHeightMap);
            conf.set("height_map_size", _heightMapSize);
            conf.set("render_bin_number", _renderBinNumber);
            conf.set("mask_layer", _maskLayerName);
            return conf;
        }

    protected:
        void mergeConfig( const osgEarth::Config& conf ) {
            osgEarth::Util::OceanOptions::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("use_height_map", _useHeightMap);
            conf.get("height_map_size", _heightMapSize);
            conf.get("render_bin_number", _renderBinNumber);
            conf.get("mask_layer", _maskLayerName);
        }

    private:
        osgEarth::optional<std::string> _user;
        osgEarth::optional<std::string> _licenseCode;
        osgEarth::optional<std::string> _resourcePath;
        osgEarth::optional<bool>        _useHeightMap;
        osgEarth::optional<int>         _heightMapSize;
        osgEarth::optional<int>         _renderBinNumber;
        osgEarth::optional<std::string> _maskLayerName;
    };

} } // namespace osgEarth::Triton

#endif // OSGEARTH_TRITON_OPTIONS
