/*
{{copyright}}
*/

/*
{{version}}
*/

/*
{{license}}
*/

#pragma once

#include <FreeRTOSHeaders.h>
#include <sdi_toolBox/dateTime/iTimer.h>

namespace sdi_uToolBox::dateTime::FreeRTOS
{
//--------------------------------------------------------------
/**
 * @brief FreeRTOS timer implementation using the RTOS tick count.
 *
 * Implements ITimer for FreeRTOS environments, using xTaskGetTickCount()
 * to provide timing based on the RTOS tick counter.
 */
class Timer : public sdi_toolBox::dateTime::ITimer
{
  public:
  Timer();                                              // Default constructor
  ~Timer()                               = default;     // Default destructor
  Timer(const Timer &obj)                = default;     // Copy constructor
  Timer(Timer &&obj) noexcept            = default;     // Move constructor
  Timer &operator=(const Timer &obj)     = default;     // Copy assignment operator
  Timer &operator=(Timer &&obj) noexcept = default;     // Move assignment operator

  /**
   * @brief Returns the current time point using the FreeRTOS tick count.
   * @return The current time point.
   */
  [[nodiscard]] TimePoint now() const override;
};
//--------------------------------------------------------------
/* Default constructor */
inline Timer::Timer()
{
  reset();
}
//--------------------------------------------------------------
/* Get the current timepoint */
inline Timer::TimePoint Timer::now() const
{
  const auto ms = xTaskGetTickCount() * portTICK_PERIOD_MS;
  return TimePoint(Duration(ms));
}
//--------------------------------------------------------------
}     // namespace sdi_uToolBox::dateTime::FreeRTOS
