#include "include/Mole.h"
#include "ServiceManager.hpp"
#include "Server.hpp"
#include "Client.hpp"

#include "services/HelloService.hpp"
#include "services/ConnectionService.hpp"
#include "services/ListChannelsService.hpp"
#include "services/JoinChannelService.hpp"
#include "services/ListUsersService.hpp"
#include "services/HomepageService.hpp"

#include "requests/xmlrpcpp/HelloRequest.hpp"
#include "requests/xmlrpcpp/ConnectionRequest.hpp"
#include "requests/xmlrpcpp/ListChannelsRequest.hpp"
#include "requests/xmlrpcpp/ListUsersRequest.hpp"
#include "requests/xmlrpcpp/JoinChannelRequest.hpp"
#include "requests/xmlrpcpp/HomepageRequest.hpp"

using namespace mole;
using namespace serv;

ServiceManager::ServiceManager(ctx::Client * c):client(c){}

ServiceManager::~ServiceManager(){}

void
ServiceManager::loadServices(){
    if (!client)
	return;

    ctx::Server * server = client->getServer();

    /* Enregistre service HELLO */
    server->addService(std::string(NAME_SERV_HELLO), new serv::HelloService()); 
    client->addRequest(std::string(NAME_SERV_HELLO), new ctx::xmlrpcpp::HelloRequest());

    /* Enregistre service CONNECTION */
    server->addService(std::string(NAME_SERV_CONNECT), new serv::ConnectionService()); 
    client->addRequest(std::string(NAME_SERV_CONNECT), new ctx::xmlrpcpp::ConnectionRequest());
 
    /* Enregistre service LISTINGCHANNELS */
    server->addService(std::string(NAME_SERV_LISTCHANNELS), new serv::ListChannelsService()); 
    client->addRequest(std::string(NAME_SERV_LISTCHANNELS), new ctx::xmlrpcpp::ListChannelsRequest());
 
    /* Enregistre service JOINCHANNEL */
    server->addService(std::string(NAME_SERV_JOINCHANNEL), new serv::JoinChannelService()); 
    client->addRequest(std::string(NAME_SERV_JOINCHANNEL), new ctx::xmlrpcpp::JoinChannelRequest());
 
    /* Enregistre service LISTINGUSERS */
    server->addService(std::string(NAME_SERV_LISTUSERS), new serv::ListUsersService()); 
    client->addRequest(std::string(NAME_SERV_LISTUSERS), new ctx::xmlrpcpp::ListUsersRequest());
 
    /* Enregistre service GET_HOMEPAGE */
    server->addService(std::string(NAME_SERV_HOMEPAGE), new serv::HomepageService()); 
    client->addRequest(std::string(NAME_SERV_HOMEPAGE), new ctx::xmlrpcpp::HomepageRequest());
 
}

