#ifndef SAB_H
#define SAB_H
#include "PinMapping.h"
#include "ScreenConfig.h"
#include "SDCardConfig.h"
#include "RtcManager.h"
#include "ScreenManager.h"
#include "SDCardManager.h"
#include "ConnectivityManager.h"
#include "WEBServerManager.h"
#include "IOManager.h"
#include <Adafruit_SSD1306.h>
#include <RTClib.h>
#include <SD.h>

class SAB
{
  public:
    SAB();
    SAB(const PinMapping pinConfig, const ScreenConfig screenConfig, const SDCardConfig sdCardConfig, const unsigned int webServerPort);
    ~SAB()
    {
      delete _connectivityManager;
    }
    
    ScreenManager& getScreenManager();
    RtcManager& getRtcManager();
    SDCardManager& getSdCardManager();
    ConnectivityManager& getConnectivityManager();
    WEBServerManager& getWebServerManager();
    IOManager& getIoManager();
    ScreenConfig getScreenConfig() const;
    PinMapping getPinConfig() const;
    SDCardConfig getSdCardConfig() const;

    PowerInfo getPowerInfo(const unsigned char nbOfMeasures = 5) const;
    unsigned char getError() const;
  private:
    void initGPIO();
    const PinMapping _pinConfig;
    const ScreenConfig _screenConfig;
    const SDCardConfig _sdCardConfig;
    
    Adafruit_SSD1306 _display;
    ScreenManager _screenManager;
    RTC_DS3231 _rtc;
    RtcManager _rtcManager;
    SDCardManager _sdCardManager;
    ConnectivityManager *_connectivityManager;
    WEBServerManager _webServerManager;
    PCF8574 _pcf;
    IOManager _ioManager;

    unsigned char _error;
};

#endif //SAB_H
