/***************************************************************************
*                                                                          *
*  Copyright (C) Golaem S.A.  All Rights Reserved.                         *
*                                                                          *
***************************************************************************/

#pragma once

#include "glmSDKAPI.h"
#include "glmNavigationMeshLocation.h"
#include <glmVector3.h>
#include <glmNavigationMesh3.h>

namespace glm
{
    /**
	* \brief Roadmap node
	*
	* \ingroup Roadmap
	*
	* \author Golaem <dev@golaem.com> 
	*/
    class GLM_SDK_API RoadmapNode
    {
    public:
        GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

        RoadmapNode();
        ~RoadmapNode()
        {
        }

        // this constructor is used when building the graph, always on a edge
        RoadmapNode(
            const NavigationMesh3& navigationMesh,
            const NavigationMeshEdgeId& edgeId,
            const Vector3& navigationPosition,
            float stepHeight,
            float distanceToNearestObstacle);

        // this constructor is used when adding extended oriented graph with orig / dest position, can be anywhere on the cell (or even have an height)
        RoadmapNode(
            const NavigationMesh3& navigationMesh,
            const NavigationMeshLocation& location,
            float stepHeight,
            float distanceToNearestObstacle);

        RoadmapNode(const RoadmapNode& node);

        RoadmapNode& operator=(const RoadmapNode& node);

        /**
		* \name INavigationMeshLocation definitions.
		*/
        //@{
        //bool isValid() const;
        //bool updateNavigationMesh(const NavigationMesh3 & navigationMesh, const Vector3& upVector, const NavigationMeshCellId& cellId = NavigationMeshCellId(-1)) override;
        //@}

        /**
		* \brief Equality operator
		*/
        bool operator==(const RoadmapNode& waypointData) const;

        /**
		* \brief Difference operator
		*/
        bool operator!=(const RoadmapNode& waypointData) const;

        Vector3 getNavigationPositionLocal() const
        {
            return _navigationMesh->getPosFromBary(_barycentricCoordinates, _navMeshCellId);
        }

        Vector3 _barycentricCoordinates;
        NavigationMeshEdgeId _navMeshCellId;
        const NavigationMesh3* _navigationMesh;

        //NavigationMeshLocation _navMeshLocation; //-> store barycenter and cellId instead, to handle dynamic navigation meshes.

        /// The edge id to which the waypoint is associated
        NavigationMeshEdgeId _edgeId;

        /// The step height of the waypoint, positive if ascending and negative if descending
        float _stepHeight;

        /// The distance to the nearest obstacle
        float _distanceToNearestObstacle;

    private:
        //		void updateCellId();

        friend class AbstractRoadmapCreator;
    };
} // namespace glm
