#ifndef BEAM_HPP
#define BEAM_HPP

#include <godot_cpp/classes/area3d.hpp>
#include <godot_cpp/classes/capsule_mesh.hpp>
#include <godot_cpp/classes/capsule_shape3d.hpp>
#include <godot_cpp/classes/collision_shape3d.hpp>
#include <godot_cpp/classes/mesh.hpp>
#include <godot_cpp/classes/mesh_instance3d.hpp>
#include <godot_cpp/classes/shape3d.hpp>

namespace godot {
//! Area3D with a MeshInstance3D that resizes itself based on a from and to position and damages any objects that enter it. Requires a child collision shape and mesh instance. Both with Capsule primitive shapes.
class Beam : public Area3D {
    GDCLASS(Beam, Area3D);
    //! Required to be a valid godot class.
    static void _bind_methods();
public:
    //! Get child collision shape and mesh instance. Assumes both have a Capsule primitive shape. Creates copies collision and mesh shapes.
    virtual void _enter_tree() override;
    //! Destroy self after end time passes.
    virtual void _process(double delta_time) override;
    //! Deal damage on whatever enters this node. Configure what to damage using collision mask.
    void body_entered(Node3D *node);
    //! Transform self and shapes to stretch from -> to.
    void set_from_to(Vector3 from, Vector3 to);
    //! Pass in a duration and set the destroy timer for this object.
    void set_end_time(float time_from_now);
private:
    MeshInstance3D *mesh_instance{nullptr};
    Ref<CapsuleMesh> mesh{};
    CollisionShape3D *collision_shape{nullptr};
    Ref<CapsuleShape3D> shape{};
    float end_time{0.f};
};
}

#endif // !BEAM_HPP
