#pragma once

#include <algorithm>
#include <box2d/box2d.h>
#include <cmath>
#include <functional>
#include <numbers>
#include <raylib.h>
#include "draw.h"

struct Info {
  float player_x;
  float player_y;
  float ball_x;
  float ball_y;
  float ball_vel_x;
  float ball_vel_y;
};

struct Action {
  bool jump;
  float move_to_x;
};

class Player {
  b2BodyId player_id;
  b2ShapeId player_shape_id;
  bool is_left;
  b2BodyId ball_id;
  std::function<Action(const Info&)> controller_function;
  bool on_ground;
  Texture2D player_texture;

  void jump();
  void move_to(float x) const;

public:
  Player(b2WorldId world_id, b2BodyId ball_id, bool is_left);
  ~Player();
  void update();
  void set_controller_function(std::function<Action(const Info&)> func);
  [[nodiscard]] b2ShapeId get_shape_id() const;
  void draw() const;
};
