/****************************************************************************
**
** Copyright (C) 2012 Róbert Márki
**
** This file is part of Web Feeds.
**
** Web Feeds is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Web Feeds is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Web Feeds.  If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#ifndef WEBSERVICEREPLY_H
#define WEBSERVICEREPLY_H
#include <QObject>
#include <QSharedPointer>
#include <QWeakPointer>
#include <QVariant>

class WebServiceClient;
class WebServiceReply;
typedef QSharedPointer<WebServiceReply> WebServiceReplyPtr;
typedef QWeakPointer<WebServiceReply> WebServiceReplyWeakRef;
class WebServiceReply : public QObject
{
    Q_OBJECT

public:
    enum CompletedState
    {
        CsNotCompleted,
        CsFinished,
        CsAborted,
        CsFailed
    };
    enum Role
    {
        RlUndefined,
        RlUpdate,
        RlCommit
    };

    WebServiceReply();
    virtual ~WebServiceReply();
    int error() const;
    void abort();
    int requestType() const;
    virtual WebServiceReply::Role role() const = 0;
    WebServiceReply::CompletedState completedState() const;

protected:
    void setError(int error);
    void setCompletedState(WebServiceReply::CompletedState completedState);
    void setRequestType(int requestType);

private:
    int m_error;
    WebServiceReply::CompletedState m_completedState;
    int m_requestType;

signals:
    void finished(WebServiceReplyPtr reply);
    void aborted(WebServiceReplyPtr reply);
    void failed(WebServiceReplyPtr reply);
    void completed(WebServiceReplyPtr reply, WebServiceReply::CompletedState state);
    void abortRequested(WebServiceReplyPtr reply);

    friend class WebServiceClient;
};
Q_DECLARE_METATYPE(WebServiceReplyWeakRef)

inline uint qHash(const WebServiceReplyWeakRef &reply)
{
    return qHash(reply.data());
}
#endif // WEBSERVICEREPLY_H
