#include <SDL2/SDL_gpu.h>

#include "physics/static_body.h"
#include "nodes/node.h"
#include "engine/window.h"

StaticBody::StaticBody(float size_x, float size_y) : Node()
{
    if (scene != nullptr)
    {
        size = Vec2(size_x, size_y);
        bBodyDef.position.Set(worldPosition.x, worldPosition.y);
        bBody = scene->b_world.CreateBody(&bBodyDef);
        bShape.SetAsBox(size.x, size.y);
        bBody->CreateFixture(&bShape, 0.0f);
    }
    else
    {
        Util::log(ERROR, "Failed to initialize physics, scene is nullptr", __FILE__, __LINE__);
    }
}

StaticBody::~StaticBody() {

}

void StaticBody::update()
{
    // Call Baseclass update
    Node::update();

    // Call logic updates here

    // Call render for graphical elements
    render();
}

void StaticBody::render()
{
    SDL_Color color = {50, 50, 50, 100};
    Vec2 position_offset = (worldPosition + localPosition);
    GPU_Rectangle(Window::windowTarget,
                  position_offset.x,
                  position_offset.y,
                  position_offset.x + size.x,
                  position_offset.y + size.y,
                  color);
}