#ifndef SYNCSCHEDULER_H
#define SYNCSCHEDULER_H

#include <QObject>
#include <QTimer>
#include <QDateTime>
#include <QSettings>
#include "core/eventbus.h"
#include "core/events.h"

class SyncScheduler : public QObject
{
    Q_OBJECT
public:
    explicit SyncScheduler(QObject *parent = nullptr);
    ~SyncScheduler() override = default;

    // Start the scheduler
    void start();
    
    // Stop the scheduler
    void stop();
    
    // Manually trigger a sync (for testing or manual sync)
    void triggerSync();

private slots:
    void onTimerTick();
    void performSync();

private:
    QTimer* m_syncTimer;
    const int m_syncIntervalMinutes = 60; // Check every hour
    const int m_minDaysBetweenSync = 3;   // Minimum 3 days between syncs
    const int m_runHour = 5;              // Only sync after 5 AM
    
    // Helper methods
    bool shouldRunSync() const;
    qint64 getLastSyncTimestamp() const;
    void setLastSyncTimestamp(qint64 timestamp);
};

#endif // SYNCSCHEDULER_H