#ifndef LEDH
#define LEDH

#include "Arduino.h"
#include "vector"
#include "board.h"

enum e_ledcolor
{
  YELLOW,
  RED,
  GREEN,
  YELLOW2,
  RED2,
  GREEN2,
  NONE
};

class c_ledport
{
  const uint32_t _pin;
  const uint32_t _analogPin;
  const uint16_t _index;
  const bool _invert;
  bool _state;

public:
  c_ledport(uint32_t pin, uint32_t analogpin, uint16_t index, bool invert = false)
      : _pin(pin), _analogPin(analogpin), _index(index), _invert(invert){};

  void begin(void);

  void turnOn(void);

  void turnOff(void);

  void writeLed(bool state);

  bool getLedState( void ) {return _state; }

  uint16_t ledRead(void);

  uint16_t getIndex(void) { return _index; }
};

class c_led
{
  const e_ledcolor _color;
  const uint16_t _value;
  const uint16_t _index;

public:
  c_led(e_ledcolor color, uint16_t value, uint16_t index)
      : _color(color), _value(value), _index(index){};

  bool checkThreshold(uint16_t value);
  bool checkcolor(e_ledcolor color);
  bool checkIndex(uint16_t index);
};

class c_leds
{
  std::vector<c_ledport> v_ledports;
  std::vector<c_led> v_leds;

public:
  c_leds(){};

  void init();

  void AddLed(uint32_t pin, uint32_t analogpin, uint16_t index, uint16_t value, e_ledcolor color, bool invert);
  void begin(void);

  void turnOnLed(e_ledcolor color);
  void turnOnLed(uint16_t index);
  void turnOffLed(e_ledcolor color);
  void turnOffLed(uint16_t index);

  c_ledport *getLed(e_ledcolor color);
  c_ledport *getLed(uint16_t index);

  bool verifyLed(e_ledcolor color);
  bool verifyLed(uint16_t index);


  void turnAllOff(void);
};

c_leds *getledlist(void);
void initLeds(void);

void turnOnLed(e_ledcolor color);
void turnOffLed(e_ledcolor color);
void turnOffLed(uint16_t index);
void turnOnLed(uint16_t index);
void turnOffAllLed();

#endif //LEDH

