#ifndef KONASEARCH_H
#define KONASEARCH_H

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

#include "konaclient.h"
#include "konaimage.h"

class KonaSearch : public QObject
{
    Q_OBJECT
public:
    KonaSearch(KonaClient *Kc,  QString Tags = "", int Page=1, int Limit = 50);
    ~KonaSearch();
    QString getTags() {return tags;}
    int getPage() {return page;}
    int getLimit() {return limit;}
    void searchAgain();
    QList<KonaImage*> getImages() {return result;}
    bool isDone() {return searchIsDone;}
    void newSearch(QString Tags = "", int Page=1, int Limit = 50);
    int getTotalImages() {return totalImages;}
    int getOffset() {return offset;}

private:
    KonaClient *kc;

    QString tags;
    int page;
    int limit;

    QHttp *http;
    QFile *file;
    int statusCode;

    int searchIsDone;

    QList<KonaImage*> result;
    int totalImages;
    int offset;

signals:
    void searchFinished(KonaSearch *ks);
    void searchFailed(KonaSearch *ks, int errorCode);

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

#endif // KONASEARCH_H
