#ifndef NLP_SERVICE_SERVICE_H
#define NLP_SERVICE_SERVICE_H

#include <map>
#include <boost/property_tree/ptree.hpp>
#include <boost/shared_ptr.hpp>

#include "logger.h"
#include "taskmanager.h"

namespace nlp_service {

/* Main class of the nlp_service. In order to write your own service subclass it
 * and override pure virtual process function.
 * You can then use some of the functions in utility.cpp to run the service.
 */
class Service {
public:
	typedef boost::property_tree::ptree service_config;
	typedef TaskManager::task_config task_config;

	Service(const std::string& config_path, std::string logfile_path = "",
			logging_lvl log_lvl = INFO_LVL, bool run_as_daemon = false);
	virtual ~Service();

	/* Utility function, so we can run the whole machinery from this class. This way the user
	 * doesn't have to care about the implementation of the other classes in the library.
	 * Initializes ServiceManager and invokes ServiceManager::run.
	 *
	 * ATTENTION: Do NOT override this function unless you are REALLY certain of what you're doing!
	 */
	void run() const;

	/* Main service function. This is the function to be overriden in the subclasses in order to
	 * get work done. It takes as argument:
	 * - task_path - the path to the file with the data to be processed
	 * - task_options - map containing options of the current job. Currently its just map<string, string>
	 * so some conversions can be required. Options should come with the task description from the tasker.
	 * - output_path - the path where we want the result file to go
	 */
	virtual void process(std::string task_path, task_config task_options, std::string output_path) const = 0;
protected:
	ServiceLoggerPtr logger;
	service_config config;
	bool run_as_daemon;
private:
	service_config read_config_file(const std::string& config_path);
};

typedef boost::shared_ptr<const Service> ServicePtr;

std::map<std::string, std::string> read_cmdln_options(int argc, char** argv);


}	// end namespace nlp_service

#endif // NLP_SERVICE_SERVICE_H
