/*=========================================================================

   Library: iMSTK

   Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
   & Imaging in Medicine, Rensselaer Polytechnic Institute.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0.txt

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

=========================================================================*/

#pragma once

#include "imstkCollisionData.h"

#include <memory>

namespace imstk
{
class CollidingObject;
//class CollisionData;
//class CollisionData::CollisionData;

///
/// \class CollisionDetection
///
/// \brief Base class for all collision detection classes
///
class CollisionDetection
{
public:

    ///
    /// \brief Type of the collision detection
    ///
    enum class Type
    {
        UnidirectionalPlaneToSphere,
        BidirectionalPlaneToSphere,
        SphereToCylinder,
        SphereToSphere,
        PointSetToSphere,
        PointSetToPlane,
        MeshToMesh,
        PointSetToCapsule,
        PointSetToSpherePicking,
        MeshToMeshBruteForce,
        Custom
    };

    ///
    /// \brief Static factory for collision detection sub classes
    ///
    static std::shared_ptr<CollisionDetection> makeCollisionDetectionObject(const Type& type,
                                                                            std::shared_ptr<CollidingObject> objA,
                                                                            std::shared_ptr<CollidingObject> objB,
                                                                            std::shared_ptr<CollisionData> colData);

    ///
    /// \brief Constructor
    ///
    CollisionDetection(const Type& type, std::shared_ptr<CollisionData> colData) :
        m_type(type)//,
        //m_colData(colData)
    {
        if (colData == nullptr)
        {
            m_colData = std::make_shared<CollisionData>();
        }
        else
        {
            m_colData = colData;
        }
    }

    CollisionDetection() = delete;

    ///
    /// \brief Destructor
    ///
    virtual ~CollisionDetection() = default;

    ///
    /// \brief Detect collision and compute collision data (pure virtual)
    ///
    virtual void computeCollisionData() = 0;

    ///
    /// \brief Returns collision detection type
    ///
    const Type& getType() const;

    ///
    /// \brief Returns collision data
    ///
    const std::shared_ptr<CollisionData> getCollisionData() const;

protected:

    Type m_type = Type::Custom;  ///< Collision detection algorithm type
    std::shared_ptr<CollisionData> m_colData;    ///< Collision data
};
}

