/*
 * ButtonEventsHandler.h
 *
 *  Created on: 19 nov. 2023
 *      Author: remi.heredero
 */

#ifndef BUTTON_BUTTONEVENTSHANDLER_H_
#define BUTTON_BUTTONEVENTSHANDLER_H_

#include "xf/behavior.h"
#include "interface/buttonscontrollercallbackprovider.h"
#include "interface/buttoneventshandlersubject.h"
#include "interface/buttoneventshandlerobserver.h"
#include "button/ButtonStateSm.h"

#define MAX_OBSERVER 5

class ButtonEventsHandler : public XFBehavior, public interface::ButtonsControllerCallbackProvider, public interface::ButtonEventsHandlerSubject {
public:
	~ButtonEventsHandler() override = default;
	static ButtonEventsHandler* getInstance();

	void onButtonChangeState(uint16_t buttonIndex, bool pressed);

	virtual bool subscribe(interface::ButtonEventsHandlerObserver* observer);
	virtual void unsubscribe(interface::ButtonEventsHandlerObserver* observer);

	virtual void notifyButtonShortPressed(ButtonIndex buttonIndex);
	virtual void notifyButtonLongPressed(ButtonIndex buttonIndex);

protected:
	ButtonEventsHandler();
	void startButtonSM();

	XFState stRun;

	interface::ButtonEventsHandlerObserver* observer_[MAX_OBSERVER];
	ButtonStateSm buttonStateSm_[4];



};

#endif /* BUTTON_BUTTONEVENTSHANDLER_H_ */
