#ifndef EMAILLISTMODEL_H
#define EMAILLISTMODEL_H

#include <QAbstractListModel>
#include <QHash>
#include <QByteArray>
#include "../db/dao/mailitemdao.h"

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

    enum EmailRoles {
        IdRole = Qt::UserRole + 1,
        SubjectRole,
        SenderRole,
        RecipientRole,
        DateRole,
        ReadRole,
        FlaggedRole,
        AttachmentsRole,
        FileIdRole,
        SizeRole,
        MessageIdRole,
        SenderInitialRole // computed from sender
    };

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;

    // Set the folderId to filter emails; -1 means all folders
    void setFolderId(int folderId);
    // Refresh the model from the database based on current folderId
    void refresh();

private:
    QVector<MailItem> m_emails;
    int m_folderId{-1}; // -1 means all folders
    // REMOVED: MailItemDao& m_mailItemDao; // Methods are static, no instance needed
};

#endif // EMAILLISTMODEL_H