#ifndef BAROMETERACTIVITYSENSOR_H
#define BAROMETERACTIVITYSENSOR_H

#include <Indoor/sensors/pressure/ActivityButterPressure.h>
#include <Indoor/misc/Debug.h>
#include "BarometerSensor.h"
#include "AccelerometerSensor.h"
#include <iostream>

struct ActivityData {
    ActivityButterPressure::Activity curActivity;
	ActivityData(const ActivityButterPressure::Activity act) : curActivity(act) {;}
    ActivityData() : curActivity(ActivityButterPressure::Activity::STAY) {;}
};

/**
 * step-sensor detects steps from the accelerometer
 */
class ActivitySensor :
		public SensorListener<BarometerData>,		// << takes
		public SensorListener<AccelerometerData>,	// << takes
		public Sensor<ActivityData> {				// << provides

private:

	ActivityButterPressure act;
    ActivityData data;

	BarometerSensor& baro;
	AccelerometerSensor& acc;

    int waitCnt = 0;

public:

	ActivitySensor(BarometerSensor& baro, AccelerometerSensor& acc) : baro(baro), acc(acc) {
		baro.addListener(this);
		acc.addListener(this);
	}

	virtual void start() override {
		// not needed
        waitCnt = 400; //sec
	}

	virtual void stop() override {
		// not needed
	}

	bool isRunning() const override {
		return acc.isRunning() && baro.isRunning();
	}

	virtual void onSensorData(Sensor<BarometerData>* sensor, const Timestamp ts, const BarometerData& data) override {
		(void) sensor;

        //ignore the first 10sec of barometer
        if(waitCnt > 0){
            --waitCnt;
            return;
        }

        this->data.curActivity = act.add(ts, data);
        informListeners(ts, this->data);

	}

	virtual void onSensorData(Sensor<AccelerometerData>* sensor, const Timestamp ts, const AccelerometerData& data) override {
		(void) sensor;
		(void) ts;
		(void) data;
		// TODO!
	}

};

#endif // BAROMETERACTIVITYSENSOR_H
