#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 "TaskSchedulerManager.h"
#include "versions.h"
#include <Adafruit_SSD1306.h>
#include <RTClib.h>
#include <SD.h>

class SAB
{
  public:
    enum Error {RTC_BEGIN_ERR = 1, DISP_BEGIN_ERR = 2, SDCARD_INIT_ERR = 4, IO_INIT_ERR = 8};
  
    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();
    TaskSchedulerManager& getTaskSchedulerManager();
    ScreenConfig getScreenConfig() const;
    PinMapping getPinConfig() const;
    SDCardConfig getSdCardConfig() const;

    PowerInfo getPowerInfo(const unsigned char nbOfMeasures = 5) const;
    const char *getSoftVersion() 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;
    TaskSchedulerManager _taskSchedulerManager;

    uint8_t _error;
};

#endif //SAB_H
