/*
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 QUERYMANAGER_P_H
#define QUERYMANAGER_P_H

#include <kdebug.h>

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

#include "query.h"
#include "service.h"

// Namespace
namespace ServiceModel { 

class QueryManagerPrivate
{
   public:
      
      QHash < int, Service* > m_serviceContainer;
      
      typedef QHash < int, Query* > QueryList;
      QHash < int, QueryList* > m_queryContainer;
      
      virtual ~QueryManagerPrivate() {}
      
      int newId() 
      {
         static int currentId = 0;
         return currentId++;
      }
      
      int addService(Service* s, int serviceId) 
      { 
         m_serviceContainer[serviceId] = s;
         
         //get the query list for the service ready 
         m_queryContainer[serviceId] = new QueryList();
         
         return serviceId;
      }
      
      QueryList* getServiceQueryList(int serviceId)
      {
         if (m_queryContainer.contains(serviceId)) {
            kDebug() << "Go " << serviceId;
            return m_queryContainer.value(serviceId);
         } else {
            kDebug() << "NO Go " << serviceId;
            return 0;
         }
      }
      
      void addQuery(Query *query, int serviceId) 
      {
         kDebug() << "Starting add query with sId " << serviceId;
         kDebug() << "Container size: " << m_queryContainer.size();
         QueryList *ql = m_queryContainer[serviceId];
         kDebug() << "got the QL with size: " << ql->size();
         ql->insert(query->id(), query);
         kDebug() << "done with add, new QL size: " << ql->size();
      }
};

} 
#endif //QUERYMANAGER_P_H

