/* les1/clock.cpp
 * Assignment done in the first lesson explaining
 * the basics of ROS2
 *
 * Reviewed by: <x>
 * Changelog:
 * [04-09-2025] Wessel T: Implement template
 * [07-09-2025] Wessel T:
 *  - Rename {les1.cpp -> les1/clock.cpp}
 *  - Update node names to be in line with other files
 * [11-09-2025] Wessel T:
 *  - Remove unused imports
 *  - Wrap into namespace
 */

#include <cstdlib>

#include "rclcpp/rclcpp.hpp"

namespace lessons::one::clock {

class NodeClock : public rclcpp::Node {
public:
    NodeClock()
    : Node("node_les1_clock")
    {
        timer_ = this->create_wall_timer(
            std::chrono::seconds(1),
            std::bind(&NodeClock::print_time, this)
        );
    }

    void print_time() {
        auto now = clock_.now();
        RCLCPP_INFO(this->get_logger(), "Time: %.0f", now.seconds());
    }

private:
    rclcpp::TimerBase::SharedPtr timer_;
    rclcpp::Clock clock_;
};

} // namespace lessons::one::clock

int main(int argc,char *argv[]) {
    rclcpp::init(argc,argv);

    auto node = std::make_shared<lessons::one::clock::NodeClock>();

    rclcpp::spin(node);
    rclcpp::shutdown();

    return 0;
}
