#ifndef UNIFIED_MANAGER_HPP
#define UNIFIED_MANAGER_HPP

#include "serialComm.hpp"
#include <memory>
#include <thread>
#include <atomic>
#include <mutex>
#include <chrono>

// Unified device manager (Serial only)
class UnifiedDeviceManager {
private:
    std::unique_ptr<SerialComm> m_serial;

    std::thread m_serialReconnectThread;
    std::atomic<bool> m_serialConnected;
    std::atomic<bool> m_shouldStop;

    std::mutex m_serialMutex;

    int m_retryIntervalMs;

    void serialReconnectThreadFunc();

public:
    UnifiedDeviceManager(int retryIntervalMs = 500);
    ~UnifiedDeviceManager();

    void start();
    void stop();

    bool isSerialConnected() const { return m_serialConnected.load(); }

    // Serial operations (thread-safe)
    bool sendData(const char* data, size_t length);
    int receiveData(uint8_t* buffer, size_t maxLength);
};

#endif // UNIFIED_MANAGER_HPP
