#pragma once
#include "Component.h"
#include <glm/glm.hpp>
#include "box2d/box2d.h"

class PhysicsComponent : public Component {
public:
    enum class BodyType { Static, Dynamic, Kinematic };

    PhysicsComponent(Object* owner, BodyType type = BodyType::Dynamic, float width = 1.0f, float height = 1.0f);
    ~PhysicsComponent();

    void CreateBody(b2WorldId world, const glm::vec2& position);
    void DestroyBody();

    void SetVelocity(const glm::vec2& vel);
    glm::vec2 GetVelocity() const;

    void SetFriction(float friction);
    float GetFriction() const;

    void SetDensity(float density);
    float GetDensity() const;

    void SetFixedRotation(bool fixed);
    bool IsFixedRotation() const;

    void SetBodyType(BodyType type);
    BodyType GetBodyType() const;

    void SetSize(float width, float height);
    float GetWidth() const;
    float GetHeight() const;

    bool HasBody() const;

    void SyncFromPhysics();
    void SyncToPhysics();

    b2BodyId GetBodyId() const { return body; }
    b2WorldId GetWorldId() const { return world; }

private:
    b2WorldId world = { 0 };
    b2BodyId body = { 0 };
    BodyType type;
    float width, height;
    float friction = 0.3f;
    float density = 1.0f;
    bool fixedRotation = false;
};
