#ifndef __Stairs
#define __Stairs

#include "./components/PCA9685.h"
#include "./config.h"
#include "./settings/steps.h"

struct Step
{
  uint8_t currentValue;
  uint8_t startValue;
  uint8_t targetValue;
  int16_t startTime;
  uint16_t remainingTime;
};


class Stairs
{
  private:
    PCA9685* mPWMDriver;
    Step mStep[MaxStepCount];

    uint32_t mLastTransitionTime;
    bool mTick = false;

  protected:
    uint8_t ease(uint8_t startValue, uint8_t targetValue, uint16_t transitionTime, uint16_t elapsedTime);
    inline void updateCurrentValue(Step* stepState);
    inline void applyCurrentValue(uint8_t step);
    uint16_t getPWMValue(uint8_t step, uint8_t brightness);

  public:
    void init(PCA9685* pwmDriver);
    void tick();

    bool inTransition() { return mTick; }

    uint8_t get(uint8_t step, bool target = true);
    void set(uint8_t step, uint8_t brightness, uint16_t transitionTime = 0, uint16_t startTime = 0);
    void setAll(uint8_t brightness, uint16_t transitionTime = 0, uint16_t startTime = 0);
    void sweep(uint8_t brightness, uint16_t transitionTime, bool topDown);
};

#endif