#pragma once

#include "../databasemanager.h"
#include "../../core/mailitem.h"
#include <QVector>
#include <optional>

struct StoredAttachmentRecord
{
    QString fileName;
    QString mimeType;
    QString contentId;
    qint64 size{0};
    QString storedPath;
};

class MailItemDao
{
public:
    static bool insert(MailItem& item);
    static bool upsert(MailItem& item);
    static bool update(const MailItem& item);
    static bool remove(qint64 id);
    static std::optional<MailItem> findById(qint64 id);
    static QVector<MailItem> findAll();
    static QVector<MailItem> findByFolderId(int folderId);
    static QVector<MailItem> findByFolderIdSinceUid(int folderId, qint64 sinceUid);
    static std::optional<qint64> maxUidForFolder(int folderId);
    static QVector<qint64> getUidsForFolder(int folderId);
    static QVector<qint64> uidsForFolder(int folderId);
    static std::optional<MailItem> findByUid(int folderId, qint64 uid);
    static bool removeByUid(int folderId, qint64 uid);
    static bool replaceAttachments(qint64 mailItemId, const QVector<StoredAttachmentRecord>& attachments);
    static QVector<StoredAttachmentRecord> attachmentsForMail(qint64 mailItemId);
};
