//===-- rosa/agent/Reliability.h --------------------------------*- C++ -*-===//
//
//                                 The RoSA Framework
//
//===----------------------------------------------------------------------===//
///
/// \file rosa/agent/Reliability.h
///
/// \author Daniel Schnoell (danielschnoell@tuwien.ac.at)
///
/// \date 2019
///
/// \brief Declaration of `rosa::Reliability` base-class.
///
//===----------------------------------------------------------------------===//

#ifndef ROSA_AGENT_RELIABILITY_H
#define ROSA_AGENT_RELIABILITY_H

#include "rosa/agent/Functionality.h"
#include "rosa/agent/LinearFunction.h"

#include <vector>

namespace rosa {
namespace agent {

template <typename Type> class Reliability_LowLevel : public Functionality {

  std::vector<Type> Sensor_History;


  float getRelibility(
      float actualValue, float lastValue,
      unsigned int valueSetCounter /*, int actualScore, int lastScore*/) {

    float rel, relAbs, relSlo;

    relAbs = getAbsoluteReliability(actualValue);
    relSlo = getSlopeReliability(actualValue, lastValue,
                                 valueSetCounter /*, actualScore, lastScore*/);

    // calculate signal input reliability
    // NOTE: options would be multiply, average, AND (best to worst:
    // average = AND > multiply) rel = relAbs * relSlo; rel = (relAbs +
    // relSlo)/2;
    rel = std::min(relAbs, relSlo);

    return rel;

    /*
    if (relAbs <= relSlo)
            return relAbs;
    else
            return relSlo;
    */
  }

  Type getInputReliability(float actualSensorValue) {

    float inputReliability;
    float previousSensorValue;

    if (Sensor_History.size() > 0) {
      inputReliability = reliabilityModule->getRelibility(
          actualSensorValue, previousSensorValue,
          mountedAgent->getValueSetCounter());
    } else {
      inputReliability =
          reliabilityModule->getAbsoluteReliability(actualSensorValue);
    }
#ifdef PRINT
    printf("rel = %f\n", inputReliability);
#endif // PRINT

    return inputReliability;
  }
};

} // namespace agent
} // namespace rosa

#endif // !ROSA_AGENT_RELIABILITY_H
