#ifndef NOTIFICATIONMANAGER_H
#define NOTIFICATIONMANAGER_H

#include <QObject>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
//// QSoundEffect disabled (unavailable, sound disabled)
#include <QIcon>
#include "core/eventbus.h"
#include "../core/events.h"

class NotificationManager : public QObject
{
    Q_OBJECT
public:
    explicit NotificationManager(QObject *parent = nullptr);
    ~NotificationManager() override;
    void initialize(); // Initialize Qt components after QApplication is ready

signals:
    void showHideRequested();

private slots:
    void onMailItemAdded(const WinoMail::Events::MailItemAddedEvent& event);
    void onMailItemRemoved(const WinoMail::Events::MailItemRemovedEvent& event);
    void onMailItemUpdated(const WinoMail::Events::MailItemUpdatedEvent& event);
    void onAccountConnected(const WinoMail::Events::AccountConnectedEvent& event);
    void onAccountDisconnected(const WinoMail::Events::AccountDisconnectedEvent& event);
    void onSyncStarted(const WinoMail::Events::SyncStartedEvent& event);
    void onSyncFinished(const WinoMail::Events::SyncFinishedEvent& event);
    void onErrorOccurred(const WinoMail::Events::ErrorEvent& event);
    void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
    void onShowHideRequested();
    void onQuitRequested();

private:
    QSystemTrayIcon* m_trayIcon;
    QMenu* m_trayMenu;
    QAction* m_showHideAction;
    QAction* m_quitAction;
    void* m_newMailSound = nullptr;  // was QSoundEffect* (disabled)
    void* m_errorSound = nullptr;  // was QSoundEffect* (disabled)

    void setupTrayIcon();
    void setupConnections();
    void playNewMailSound();
    void playErrorSound();
    void showNotification(const QString& title, const QString& message, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int timeout = 5000);
};

#endif // NOTIFICATIONMANAGER_H