#ifndef CONNECTIVITYMANAGER_H
#define CONNECTIVITYMANAGER_H

#include <ESP8266WiFi.h>
#include "SDCardManager.h"
#include "CFGFileParser.h"
#include "CFGDictionary.h"
#include "definition.h"

#define MIN_RSSI -90
#define MAX_RSSI -50
#define COEF_RSSI 2.5

#define STA_ENABLED_DISABLE_ERR B00001000
#define AP_ENABLED_DISABLE_ERR  B00000001
#define AP_SETUP_ERR            B00000010
#define STA_SETUP_ERR           B00000100

class ConnectivityManager : public ESP8266WiFiClass
{
  friend class SAB;
  public:
    boolean connect();
    boolean enableSTAAndAP(boolean enable);
    boolean isSTAEnabled();
    boolean isAPEnabled();
    
    unsigned char RSSIPercent();
    unsigned char getError() const;
  protected:
    ConnectivityManager(bool persistent = false);
    ConnectivityManager(SDCardManager &sdCardManager, bool persistent = false);

    boolean connectToSTA();
    boolean startAP();
  private:
    unsigned char _error = NO_ERROR;
    SDCardManager *_sdCardManager = nullptr;
};

#endif //CONNECTIVITYMANAGER_H
