#pragma once
#include <wx/wx.h>
#include <wx/thread.h>

///Custom event used to send updated component data from the manager thread back to the UI.
wxDECLARE_EVENT(wxEVT_RUMPI_UPDATE, wxThreadEvent);

/**
* Background wxThread that runs the RumPi library's sensor loop and posts refreshed component data (and the curated
* dashboard snapshot) to the UI thread via wxEVT_RUMPI_UPDATE events.
*
* @author Eddie O'Hagan
* @date 8/13/2026
*/
class RumPiManagerThread : public wxThread
{
protected:
	wxEvtHandler* myWxEventHandler;	///< The UI event handler that receives component-update events.

public:
	/**
	* Builds the manager thread (joinable) and stores the UI handler. The RumPi library is initialized later, on the
	* worker thread at the top of Entry() (not here), so every library call happens on the one worker thread.
	*
	* @author Eddie O'Hagan
	* @date 8/13/2026
	*
	* @code
	*	RumPiManagerThread* thread = new RumPiManagerThread(this);
	*	thread->Run();
	* @endcode
	*
	* @param [in] handler The UI event handler to post component updates to.
	*/
	RumPiManagerThread(wxEvtHandler* handler);

	/**
	* Destroys the thread, waiting for it to finish first.
	*
	* @author Eddie O'Hagan
	* @date 8/13/2026
	*
	* @code
	*	delete thread;
	* @endcode
	*/
	virtual ~RumPiManagerThread();

	/**
	* Thread body: starts the library, then loops on a fast tick (~100ms) fast-sampling the wind/motion/light sensors
	* every tick, and on a slower wall-clock cadence (~2s) refreshes all components and posts their data plus the
	* dashboard snapshot to the UI, until the thread is asked to exit.
	*
	* @author Eddie O'Hagan
	* @date 8/13/2026
	*
	* @code
	*	//Run by wxWidgets when the thread starts.
	* @endcode
	*
	* @return The thread's exit code (always 0).
	*/
	virtual wxThread::ExitCode Entry() override;
};
