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

#ifndef OSGEARTHSYMBOLOGY_INSTANCE_RESOURCE_H
#define OSGEARTHSYMBOLOGY_INSTANCE_RESOURCE_H 1

#include <osgEarth/Common>
#include <osgEarth/Resource>
#include <osgEarth/InstanceSymbol>
#include <osgEarth/URI>
#include <map>

namespace osgEarth { namespace Util
{
    /**
     * A resource that materializes an InstanceSymbol, which is a single-point object
     * that resolves to an osg::Node. Instances are usually used for point-model
     * substitution.
     */
    class OSGEARTH_EXPORT InstanceResource : public Resource
    {
    public:

        /** dtor */
        virtual ~InstanceResource() { }

        /**
         * Creates a new Node representing the instance.
         */
        osg::Node* createNode(const osgDB::Options* readOptions) const;

        /** Whether this instance type is 2D (orthographic screen space) */
        virtual bool is2D() const =0;

    public:
        /** Source location of the actual data to load.  */
        optional<URI>& uri() { return _uri; }
        const optional<URI>& uri() const { return _uri; }

        //! For programmaticly set nodes only
        osg::ref_ptr<osg::Node>& node() { return _node; }
        const osg::ref_ptr<osg::Node>& node() const { return _node; }

    public: // serialization methods

        virtual Config getConfig() const;
        void mergeConfig( const Config& conf );

    protected:
        /** Constructs a new resource. */
        InstanceResource( const Config& conf =Config() );

        optional<URI> _uri;
        osg::ref_ptr<osg::Node> _node;

        virtual osg::Node* createNodeFromURI( const URI& uri, const osgDB::Options* dbOptions ) const =0;
    };
} }

#endif // OSGEARTHSYMBOLOGY_MARKER_RESOURCE_H
