#ifndef KONATAGS_H
#define KONATAGS_H

#include <QObject>
#include <QHttp>
#include <QFile>
#include <QUrl>
#include <QtXml>

#include "konatag.h"
#include "konaclient.h"

#define ERROR_TAGS_TEMPFILE 1
#define ERROR_TAGS_FORMAT 2
#define ERROR_SEARCH_XML 3
#define ERROR_SEARCH_HTTP 4

class KonaTags : public QObject
{
    Q_OBJECT
public:
    // order can be date, count or name
    KonaTags(KonaClient *Kc, QString Name, int Limit=20, int Page=1, QString Order="count", int Id = -1, int AfterId = -1, QString NamePattern="");
    void searchAgain();
    bool isDone() {return searchIsDone;}
    QList<KonaTag*> getTags() {return result;}
    void newSearch(QString Name = "__KEEPOLD__", int Limit = -1, int Page = -1, QString Order="__KEEPOLD__", int Id = -1, int AfterId = -1, QString NamePattern = "__KEEPOLD__");

private:
    KonaClient *kc;
    QString name;
    int limit;
    int page;
    QString order;
    int id;
    int afterId;
    QString namePattern;

    QHttp *http;
    QFile *file;
    int statusCode;

    int searchIsDone;

    QList<KonaTag*> result;

signals:
    void searchFinished(KonaTags *kt);
    void searchFailed(KonaTags *kt, int errorCode);

public slots:
    void requestFinished();
    void responseHeaderReceived(QHttpResponseHeader resp);
};

#endif // KONATAGS_H
