#ifndef ALARMTIME_H
#define ALARMTIME_H
#include <QDateTime>
#include <QObject>
#include <QRunnable>
#include <QScopedPointer>
#include <QEventLoop>
#include <QTimer>
#include <QProcess>
#include <QDebug>
#include <stdint.h>

#include "actor.h"

class AlarmTime :  public Actor, public QRunnable
{
	Q_OBJECT
public:
	static const uint8_t REPEAT_NEVER = 0;
	static const uint8_t REPEAT_DAILY = 1;
	static const uint8_t REPEAT_WEEKLY = 2;
	static const uint8_t REPEAT_MONTHLY = 3;
	static const uint8_t REPEAT_YEARLY = 4;

private:

	bool triggerd_ = false;
	QDateTime time_;
	QTimer timer;
	uint8_t repeat_ = REPEAT_NEVER;

public:
	explicit AlarmTime(const QDateTime time = QDateTime::currentDateTime(), QObject *parent = nullptr);
	~AlarmTime();

	QDateTime getDateTime();

	virtual void store(QJsonObject& json);
	virtual void load(const QJsonObject& json, const bool preserve = false);

	uint8_t getRepeat();
	virtual QString getName() const;

public slots:

	void run();
	virtual void makeActive();
	virtual void makeInactive();
	void doTick();
	void changeTime(const QDateTime& time);
	void setRepeat(const uint8_t repeat);
};

#endif // ALARMTIME_H
