/*
  Copyright (c) 2025-2026 Kay Kasper
  under the MIT License (MIT)
*/

#ifndef CLASSES_TESTSWITCH
#define CLASSES_TESTSWITCH

#include <Switch.h>
#include <SwitchExtensions.h>
#include <RotaryEncoder.h>

/*
  Subclass of class SwitchLocal, that implements functionality for testing.
*/
class TestSwitch : public Switch {
  private:
    int _internalState;

  public:
    TestSwitch(uint8_t numState, uint8_t* bufferMapping, uint8_t inputPin, 
              uint8_t readCycleMillis, uint8_t debounceMillis, bool invertRaw)
      : Switch(numState, bufferMapping, inputPin, readCycleMillis, debounceMillis, invertRaw){};

    TestSwitch(SwitchStateAnalyzer* ssa, bool enableMapping, uint8_t inputPin, 
              uint8_t debounceMillis, bool invertRaw)
      : Switch(ssa, enableMapping, inputPin, debounceMillis, invertRaw){};

    uint8_t getRawState(){
//      byte a = SwitchLocal::getRawState(); // for real performance, but irrelevant result for testing
      return _internalState;
    }

    void setRawState(uint8_t state){
      _internalState = state;
    }

    void setReadCycleMillis(uint8_t readCycleMillis){
      _readCycleMillis = readCycleMillis;
    }

    void setDebounceMillis(uint8_t debounceMillis){
      _debounceMillis = debounceMillis;
    }

    void setInvertRaw(bool invertRaw){
      _invertRaw = invertRaw;
    }
};


class TestPushButtonDoubleLongAnalyzer : public PushButtonDoubleLongAnalyzer {
  public:
    TestPushButtonDoubleLongAnalyzer(unsigned int maxDoubleMillis, unsigned int minLongMillis, boolean endLongByTime) : 
    PushButtonDoubleLongAnalyzer(maxDoubleMillis, minLongMillis, endLongByTime){};

    void printInternalState(){
      Serial.print("I:");Serial.println(_internalState);
    };

    void setEndLongByTime(bool endLongByTime){
      _endLongByTime = endLongByTime;
    };
};


/*
  Subclass of class RotaryEncoder, that implements functionality for testing.
*/
class TestRotaryEncoder : public RotaryEncoder {
  private:
    int _internalState;

  public:
    TestRotaryEncoder(RotaryEncoderAnalyzer* rea, bool enableMapping, uint8_t inputPinA, uint8_t inputPinB,
                   uint8_t debounceMillis, bool invertRaw)
      : RotaryEncoder(rea, enableMapping, inputPinA, inputPinB, debounceMillis, invertRaw){};

    uint8_t getRawState(){
//      byte a = RotaryEncoder::getRawState(); // for real performance, but irrelevant result for testing
      return _internalState;
    }

    void setRawState(uint8_t state){
      _internalState = state;
    }

    void setDebounceMillis(uint8_t debounceMillis){
      _debounceMillis = debounceMillis;
    }

    void setInvertRaw(bool invertRaw){
      _invertRaw = invertRaw;
    }

    void setReadCycleMillis(uint8_t readCycleMillis){
      _readCycleMillis = readCycleMillis;
    }
};

#endif
