#include "concreterequests.h"

// Gmail
GmailListMessagesRequest::GmailListMessagesRequest(const QString &accountId, const QString &folderId,
                                                     const QString &pageToken)
    : Request()
{
    setAccountId(accountId);
    setType(RequestType::GmailApi);
    setMethod(Request::Method::GET);

    // Build Gmail API URL
    // folderId for Gmail is typically "INBOX", "SENT", etc.
    QString path = QString("https://gmail.googleapis.com/gmail/v1/users/me/messages");
    QString query = QString("q=in:%1").arg(folderId.toLower());
    if (!pageToken.isEmpty()) {
        query += "&pageToken=" + pageToken;
    }
    QUrl url(path);
    url.setQuery(query);
    setUrl(url);
}

GmailGetMessageRequest::GmailGetMessageRequest(const QString &accountId, const QString &messageId)
    : Request()
{
    setAccountId(accountId);
    setType(RequestType::GmailApi);
    setMethod(Request::Method::GET);

    QUrl url(QString("https://gmail.googleapis.com/gmail/v1/users/me/messages/%1").arg(messageId));
    setUrl(url);
}

// Graph API
GraphListMessagesRequest::GraphListMessagesRequest(const QString &accountId, const QString &folderId,
                                                     const QString &deltaLink)
    : Request()
{
    setAccountId(accountId);
    setType(RequestType::GraphApi);
    setMethod(Request::Method::GET);

    // Use deltaLink if available (for incremental sync)
    if (!deltaLink.isEmpty()) {
        setUrl(QUrl(deltaLink));
    } else {
        QUrl url(QString("https://graph.microsoft.com/v1.0/me/mailFolders/%1/messages").arg(folderId));
        setUrl(url);
    }
}

GraphGetMessageRequest::GraphGetMessageRequest(const QString &accountId, const QString &messageId)
    : Request()
{
    setAccountId(accountId);
    setType(RequestType::GraphApi);
    setMethod(Request::Method::GET);

    QUrl url(QString("https://graph.microsoft.com/v1.0/me/messages/%1").arg(messageId));
    setUrl(url);
}
