// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

#pragma once

#include <IAEngine/Components/IComponent.hpp>

namespace ia::iae
{
    class PhysicsComponent : public IComponent
    {
      public:
        struct Collider
        {
            BOOL IsTrigger{false};
            Vec2 Position{};
            Vec2 Size{};
        };

      public:
        PhysicsComponent(IN Node2D *node);

        Handle CreateCollider();
        Handle AddCollider(IN Collider collider);
        Collider &GetCollider(IN Handle handle);

        VOID Move(IN glm::vec2 direction);

        VOID Jump(IN FLOAT32 force);

      public:
        BOOL &IsDynamic()
        {
            return m_isDynamic;
        }

        FLOAT32 &MovementSpeed()
        {
            return m_movementSpeed;
        }

        Vector<Collider> &Colliders()
        {
            return m_colliders;
        }

        CONST Vec2 &GetVelocity() CONST
        {
            return m_velocity;
        }

      private:
        Vec2 m_velocity{};
        BOOL m_isDynamic{false};
        Vector<Collider> m_colliders;
        FLOAT32 m_movementSpeed{1.0f};
        Handle m_physicsHandle{INVALID_HANDLE};

        VOID OnCollision(IN PhysicsComponent *other);

        friend class Physics;

      public:
        VIRTUAL VOID Draw();
        VIRTUAL VOID DebugDraw();

        VIRTUAL VOID Update();
        VIRTUAL VOID FixedUpdate();
    };
} // namespace ia::iae