#ifndef CAR_PLAYER_HPP
#define CAR_PLAYER_HPP

#include "car_physics.hpp"
#include "godot_cpp/classes/packed_scene.hpp"
#include "utils/player.hpp"
#include <godot_cpp/classes/input_event.hpp>
#include <godot_cpp/classes/rigid_body3d.hpp>
#include <godot_cpp/classes/collision_shape3d.hpp>

namespace godot {
class CarPlayer : public CarPhysics,
                  public IPlayer {
    GDCLASS(CarPlayer, CarPhysics);
    static void _bind_methods();
public:
    virtual void _ready() override;
    virtual void _process(double delta_time) override;
    virtual void setup_player_input(PlayerInput *input) override;
    virtual void spawn_at_position(Transform3D const &transform) override;
    virtual Node *to_node() override;

    void on_steer(Ref<InputEvent> event, float value);
    void on_brake(Ref<InputEvent> event, float value);
    void on_accelerate(Ref<InputEvent> event, float value);

    void damage();

    void destroy_all_powerups();
    void activate_powerup(Ref<PackedScene> scene);
    void activate_turret();
    void activate_beacon();
    void activate_shield();

    void set_turret_scene(Ref<PackedScene> scene);
    Ref<PackedScene> get_turret_scene() const;
    void set_beacon_scene(Ref<PackedScene> scene);
    Ref<PackedScene> get_beacon_scene() const;
    void set_shield_scene(Ref<PackedScene> scene);
    Ref<PackedScene> get_shield_scene() const;
private:
    int health{5};
    double end_of_powerup{0.0};

    Node3D *roof_slot{nullptr};

    Ref<PackedScene> turret;
    Ref<PackedScene> beacon;
    Ref<PackedScene> shield;

    const float max_speed{40.f};
    const float max_speed_reverse{10.f};
    const float steering_factor{0.7f};
    const float powerup_duration{10.f};
};
};

#endif // !CAR_PLAYER_HPP
