#ifndef RIGIDBODYCOMPONENT_HPP
#define RIGIDBODYCOMPONENT_HPP

#include "IPhysicsComponent.hpp"
#include "TransformComponent.hpp"
#include "TinyMath.hpp"
#include <string>

/**
 * An implementation of IPhysicsComponent to allow for physics-based collisions.
 * @see PhysicsEngine
 */
class RigidbodyComponent : public IPhysicsComponent {
public:
    /**
     * Construct a new Rigidbody Component object.
     * 
     * @param pos the TransformComponent of the parent GameObject
     * @param dim the dimensions of the Rigidbody
     * @param vel the velocity of the Rigidbody
     * @param m the mass of the Rigidbody
     * @param elastic whether the Rigidbody uses elastic collisions. Defaults to false.
     * @param grav whether the Rigidbody is affected by gravity. Defaults to false.
     */
    RigidbodyComponent(TransformComponent* pos, Vec2D dim, Vec2D vel, float m, 
                        bool elastic = false, bool grav = false);
    /**
     * Destroy the Rigidbody Component object.
     */
    ~RigidbodyComponent();

    void ApplyForce(Vec2D force) override;

    void ApplyAcceleration(Vec2D acceleration) override;

    void ApplyVelocity() override;

    /**
     * Move the RigidbodyComponent every frame.
     * {@inheritDoc}
     */
    void Update(SDL_Event e, int frame, std::vector<std::string> broadcastList) override;

    void ShowComponentEditor(bool* showEditor) override;

    const char* ComponentTypeName() override {return "Rigidbody Component";}

    // SETTERS

    void SetVelocity(Vec2D vel) override;

    // GETTERS

    /**
     * @return true for all RigidbodyComponents
     */
    bool IsKinematic() override;

    bool IsElastic() override;
    bool UsesGravity() override;
    Vec2D GetVelocity() override;
    float GetMass() override;

private:    
    Vec2D velocity;
    float mass;
    bool isElastic;
    bool usesGravity;
};

#endif