#include "alarm.h"

class LedController {
private:
  int bluePin = 32;
  int redPin = 33;
  int greenPin = 27;
  AlarmStatus* status;

  void turnOn(int led){
    digitalWrite(led, LED_ON_VAL);
  }

  void turnOff(int led){
    digitalWrite(led, LED_OFF_VAL);
  }
public:
  static const int PIN_LED_BLUE = 32;
  static const int PIN_LED_RED = 33;
  static const int PIN_LED_GREEN = 25;
  
  static const int LED_OFF_VAL = 0;
  static const int LED_ON_VAL = 255;

   LedController(AlarmStatus* statusObj){
    Serial.println("const.");
    status = statusObj;
  }
  void SetPins(int blueLedPin, int greenLedPin, int redLedPin){
    bluePin = blueLedPin;
    redPin = redLedPin;
    greenPin = greenLedPin;
  }
  void Init(){
    pinMode(bluePin, OUTPUT);
    pinMode(redPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
  }

  void Off(){
    turnOff(bluePin);
    turnOff(redPin);
    turnOff(greenPin);
  }

  void Red(){
    turnOn(redPin);
    turnOff(greenPin);
    turnOff(bluePin);
  }

  void Green(){
    turnOn(greenPin);
    turnOff(redPin);
    turnOff(bluePin);
  }

  void Yellow(){
    turnOn(redPin);
    turnOn(greenPin);
    turnOff(bluePin);
  }

  void Blue(){
    turnOn(bluePin);
    turnOff(redPin);
    turnOff(greenPin);
  }

  void Error(){
    Red();
    delay(100);

    Off();
    delay(100);

    Red();
    delay(100);

    Off();
    delay(100);
  }

  void Update(){
    if(!status->ledOn)
    {
      Off();
      return;
    }
    if(status->isFired)
    {
      Red();
      return;
    }
    if(status->doorStatus==DOOR_OPEN)
    {
      Yellow();
      return;
    }
    if(status->isArmed)
    {
      Blue();
      return;
    }
    Green();
  }
};


