#pragma once

#include <QString>
#include <QDateTime>
#include <QVector>
#include "models/account.h"
#include "models/folder.h"
#include "mailitem.h"

namespace WinoMail {
namespace Events {

// Base event class
struct BaseEvent {
    virtual ~BaseEvent() = default;
    QString eventId; // Unique identifier for the event
    QDateTime timestamp; // When the event occurred
};

// Mail item events
struct MailItemAddedEvent : public BaseEvent {
    MailItem item;
};

struct MailItemRemovedEvent : public BaseEvent {
    QString itemUid; // UID of the removed item
    int folderId;
};

struct MailItemUpdatedEvent : public BaseEvent {
    MailItem item;
    QVector<QString> changedFields; // Which fields were modified
};

// Folder events
struct FolderAddedEvent : public BaseEvent {
    Folder folder;
};

struct FolderRemovedEvent : public BaseEvent {
    QString folderId;
};

struct FolderUpdatedEvent : public BaseEvent {
    Folder folder;
    QVector<QString> changedFields;
};

// Account events
struct AccountAddedEvent : public BaseEvent {
    Account account;
};

struct AccountRemovedEvent : public BaseEvent {
    int accountId;
};

struct AccountUpdatedEvent : public BaseEvent {
    Account account;
    QVector<QString> changedFields;
};

// Sync events
struct SyncStartedEvent : public BaseEvent {
    int accountId;
    QString folderId; // Optional, empty for full account sync
};

struct SyncFinishedEvent : public BaseEvent {
    int accountId;
    QString folderId; // Optional, empty for full account sync
    bool success;
    QString errorMessage; // If success is false
};

// Connection events
struct AccountConnectedEvent : public BaseEvent {
    int accountId;
    QString provider; // "outlook", "gmail", "imap"
};

struct AccountDisconnectedEvent : public BaseEvent {
    int accountId;
    QString provider;
    QString reason; // Optional reason for disconnection
};

// Error events
struct ErrorEvent : public BaseEvent {
    QString message;
    QString source; // Which component generated the error
    bool isCritical; // Whether this error requires user attention
};

} // namespace Events
} // namespace WinoMail