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

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


enum MotionDirection
{
  Nondirectional = 1,
  TopDown = 2,
  BottomUp = 3
};


enum MotionDuringTimeTrigger
{
  Never = 0,
  Always = 1,
  Only = 2
};


struct MotionTrigger
{
  uint8_t pin;
  uint8_t brightness;
  MotionDirection direction;
  bool enabled;
};


class MotionTriggerSettings : public AbstractJsonSettings
{
  private:
    bool mEnabled = false;
    MotionDuringTimeTrigger mEnabledDuringTimeTrigger = MotionDuringTimeTrigger::Never;
    bool mEnabledDuringDay = false;
    uint16_t mTransitionTime = 500;
    uint32_t mDelay = 30000;
    uint8_t mTriggerCount = 0;
    MotionTrigger* mTriggers = nullptr;

  protected:
    virtual const char* getFilename() { return MotionTriggerSettingsFile; };
    virtual const char* getDebugPrefix() { return "MotionTriggerSettings"; };

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


    bool enabled() { return mEnabled; }
    void enabled(bool value) { mEnabled = value; }

    MotionDuringTimeTrigger enabledDuringTimeTrigger() { return mEnabledDuringTimeTrigger; }
    void enabledDuringTimeTrigger(MotionDuringTimeTrigger value) { mEnabledDuringTimeTrigger = value; }

    bool enabledDuringDay() { return mEnabledDuringDay; }
    void enabledDuringDay(bool value) { mEnabledDuringDay = value; }

    uint16_t transitionTime() { return mTransitionTime; }
    void transitionTime(uint16_t value) { mTransitionTime = value; }

    uint32_t delay() { return mDelay; }
    void delay(uint32_t value) { mDelay = value; }

    uint8_t triggerCount() { return mTriggerCount; }
    MotionTrigger* trigger(uint8_t index) { return &mTriggers[index]; }
};

#endif