#ifndef CAMERA_H
#define CAMERA_H

//    This file is part of Motion Watch.

//    Motion Watch is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.

//    Motion Watch is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.

#include "common.h"
#include "logger.h"
#include "web.h"

class Camera : public QObject
{
    Q_OBJECT

private:

    shared_t shared;

public:

    explicit Camera(QObject *parent = nullptr);

    int start(const QStringList &args);
};

class Loop : public QObject
{
    Q_OBJECT

protected:

    shared_t *shared;
    QTimer   *loopTimer;
    int       heartBeat;

protected slots:

    virtual void init();

private slots:

    void loopSlot();

public:

    explicit Loop(shared_t *shared, QThread *thr, QObject *parent = nullptr);

    virtual bool exec();
};

class RecLoop : public Loop
{
    Q_OBJECT

private:

    QProcess *recProc;
    QProcess *imgProc;
    QString   curUrl;

    void updateCmd();
    void procError(const QString &desc, QProcess *proc);

private slots:

    void init();
    void term();
    void rdProcErr();

public:

    explicit RecLoop(shared_t *shared, QThread *thr, QObject *parent = nullptr);

    bool exec();
};

class Upkeep : public Loop
{
    Q_OBJECT

public:

    explicit Upkeep(shared_t *shared, QThread *thr, QObject *parent = nullptr);

    bool exec();
};

class EventLoop : public Loop
{
    Q_OBJECT

private:

    QStringList vidList;
    QString     imgPath;
    QString     name;
    float       highScore;
    uint        cycles;

    bool wrOutVod();

public:

    explicit EventLoop(shared_t *shared, QThread *thr, QObject *parent = nullptr);

    bool exec();
};

class DetectLoop : public Loop
{
    Q_OBJECT

private:

    QTimer *pcTimer;
    uint    delayCycles;
    bool    mod;

    void resetTimers();

private slots:

    void init();
    void pcBreak();

public:

    explicit DetectLoop(shared_t *shared, QThread *thr, QObject *parent = nullptr);

    bool exec();
};

#endif // CAMERA_H
