/*
 * Stairs
 * Copyright 2017 (c) Mark van Renswoude
 *
 * https://git.x2software.net/pub/Stairs
*/
#ifndef __settingssteps
#define __settingssteps

#include <stdint.h>
#include "./abstractjson.h"
#include "../config.h"

#define MaxStepCount 16



struct StepRange
{
    uint16_t start;
    uint16_t end;
};



class StepsSettings : public AbstractJsonSettings
{
  private:
    uint8_t mCount = MaxStepCount;
    bool mUseCurve = true;
    StepRange mRange[MaxStepCount];

  protected:
    virtual const char* getFilename() { return StepsSettingsFile; };
    virtual const char* getDebugPrefix() { return "StepsSettings"; };

  public:
    StepsSettings();

    void toJson(Print &print);
    bool fromJson(char* data, bool* changed);


    uint8_t count() { return mCount; }
    void count(uint8_t value) { mCount = value; }

    bool useCurve() { return mUseCurve; }
    void useCurve(bool value) { mUseCurve = value; }

    uint16_t rangeStart(uint8_t step) { return step < MaxStepCount ? mRange[step].start : 0; }
    void rangeStart(uint8_t step, uint16_t value) { if (step < MaxStepCount) mRange[step].start = value; }

    uint16_t rangeEnd(uint8_t step) { return step < MaxStepCount ? mRange[step].end : 0; }
    void rangeEnd(uint8_t step, uint16_t value) { if (step < MaxStepCount) mRange[step].end = value; }
};

#endif