/**
 * @file swtimer.hpp
 * @brief Software Timer component header - Manages time-based events and scheduling
 * @author Mahmoud Elmohtady
 * @company Nabd solutions - ASF
 * @copyright Copyright (c) 2025
 */

#ifndef SWTIMER_HPP
#define SWTIMER_HPP

#include <cstdint>
#include <functional>

/**
 * @brief Timer type enumeration
 */
enum class TimerType
{
    ONE_SHOT,    ///< Timer expires once and stops
    PERIODIC     ///< Timer repeats until stopped
};

/**
 * @brief Timer callback function type
 */
using TimerCallback = std::function<void(void)>;

/**
 * @brief Software Timer class
 * 
 * Provides functionality to create, start, stop, and manage timers
 * that can trigger callbacks after specified intervals.
 */
class SoftwareTimer
{
public:
    /**
     * @brief Constructor
     */
    SoftwareTimer();

    /**
     * @brief Destructor
     */
    ~SoftwareTimer();

    /**
     * @brief Create a new timer
     * @param interval_ms Timer interval in milliseconds
     * @param type Timer type (ONE_SHOT or PERIODIC)
     * @param callback Function to call when timer expires
     * @return true if timer created successfully, false otherwise
     */
    bool create(uint32_t interval_ms, TimerType type, TimerCallback callback);

    /**
     * @brief Start the timer
     * @return true if started successfully, false otherwise
     */
    bool start();

    /**
     * @brief Stop the timer
     * @return true if stopped successfully, false otherwise
     */
    bool stop();

    /**
     * @brief Reset the timer
     * @return true if reset successfully, false otherwise
     */
    bool reset();

    /**
     * @brief Check if timer is active
     * @return true if timer is running, false otherwise
     */
    bool isActive() const;

    /**
     * @brief Get the timer interval
     * @return Timer interval in milliseconds
     */
    uint32_t getInterval() const;

private:
    bool m_isActive;        ///< Timer active state
    uint32_t m_interval;    ///< Timer interval in milliseconds
    TimerType m_type;       ///< Timer type
    TimerCallback m_callback; ///< Callback function
};

#endif // SWTIMER_HPP

