#ifndef SAB_H
#define SAB_H

#include "BoardConfig.h"
#include "RtcManager.h"
#include "ScreenManager.h"
#include "SDCardManager.h"
#include "ConnectivityManager.h"
//#include "WEBServerManager.h"
#include "WEBClient.h" //includes WEBServer internally
#include "FTPClient.h" //includes FTPServer internally
#include "IOManager.h"
#include "TaskSchedulerManager.h"
#include "PowerManager.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 BoardConfig boardConfig, const unsigned int webServerPort = 80, const unsigned int ftpServerPort = 21);
    ~SAB()
    {
      delete _connectivityManager;
    }
    
    ScreenManager& getScreenManager();
    RtcManager& getRtcManager();
    SDCardManager& getSdCardManager();
    ConnectivityManager& getConnectivityManager();
    //WEBServerManager& getWebServerManager();
    WEBServer<WEBClient>& getWebServer();
    FTPServer<FTPClient>& getFtpServer();
    IOManager& getIoManager();
    TaskSchedulerManager& getTaskSchedulerManager();
    PowerManager& getPowerManager();
    BoardConfig getBoardConfig() const;
    const char *getSoftVersion() const;
    unsigned char getError() const;
  private:
    void initGPIO();
    const BoardConfig _boardConfig;
    
    Adafruit_SSD1306 _display;
    ScreenManager _screenManager;
    RTC_DS3231 _rtc;
    RtcManager _rtcManager;
    SDCardManager _sdCardManager;
    ConnectivityManager *_connectivityManager;
    //WEBServerManager _webServerManager;
    WEBServer<WEBClient> _webServer;
    FTPServer<FTPClient> _ftpServer;
    PCF8574 _pcf;
    IOManager _ioManager;
    TaskSchedulerManager _taskSchedulerManager;
    PowerManager _powerManager;

    uint8_t _error;
};

#endif //SAB_H
