/*
Copyright 2008  Nathan Bradshaw nathanlbradshaw@gmail.com

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.

This library 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SMODQUERY_H
#define SMODQUERY_H

#include <QtCore/QString>
#include <QtCore/QVariant>
#include <QtCore/QHash>

#include "service.h"
#include "response.h"

#include "servicemodel_export.h"

// Namespace
namespace ServiceModel { 

class QueryPrivate;
class Service;
class Response;

class SERVICEMODEL_EXPORT Query : public QObject {
   
   Q_OBJECT
   
   public:
      /** Constructor */
      explicit Query (Service *service, QObject *parent = 0);
      
      /** Destructor */
      virtual ~Query();
      
      /** returns the query's Id number */
      int id ();
      
      /** 
      Return a reference to the service being queried.  
      Returns the base service class which is probably not very useful unless dynamically cast to child service type 
      */
      const Service* service ();
      
      /** return a QHash with the parameters for the query */
      QHash<QString, QVariant> &parameters();
      
      
      
      /** execute the query */
      virtual void execute () = 0;
      
      /** return the response the query generated */
      virtual Response* response () =0;
      
   signals :
      /**
      emitted when the query has completed processing
      @param id the query Id
      @param error a boolean indication of the error status of the query
      */
      void finished(int id, bool error);
      
            
   protected:
      /** dynamic pointer for private class */
      QueryPrivate * const d_ptr;
      
      /** Constructor */
      Query(QueryPrivate &dd, Service *service, QObject *parent);
      
      /** set the query's id */
      int setId(int id);
      
      /** Add a parameter to the query. Parameters typically provide a means of tailoring the query results returned by a service */
      void addQueryParameter (const QString key, const QVariant val);
      
      
   private:
      Q_DECLARE_PRIVATE(Query)

};
} 
#endif //SMODQUERY_H

