#ifndef OpenTestSystem_OtxDiagManager_Server_Server_H
#define OpenTestSystem_OtxDiagManager_Server_Server_H

#include "ServerDefs.h"
#include <string>
#include <functional>

namespace OpenTestSystem { namespace OtxDiagManager { namespace Common {
	class ICommandProcessor;
	class Result;
	class Exception;
}}}

namespace OpenTestSystem
{
	namespace OtxDiagManager
	{
		namespace Server
		{
			/// <summary>
			/// Contains methods for the DiagManager server
			/// </summary>
			class SERVER_DEFS Server
			{
			public:
				Server();
				virtual ~Server();
				/// <summary>
				/// Starts the DiagManager server
				/// </summary>
				/// <returns>Returns 0 if the server is started up without any problems, otherwise -1.</returns>
				virtual int Start();
				/// <summary>
				/// Stops the DiagManager server
				/// </summary>
				/// <returns>Returns 0 if the server is stoped without any problems, otherwise -1.</returns>
				virtual int Stop();
				/// <summary>
				/// Checks, if the server is alive.
				/// </summary>
				/// <returns>Returns TRUE if the server is alive, otherwise FALSE. A server is alive, if it has been started and has not yet died.</returns>
				virtual bool IsAlive();
				/// <summary>
				/// Sets the CommandProcessor for the DiagManager server
				/// </summary>
				/// <param name="processor">Instance of the CommandProcessor</param>
				void SetCommandProcessor(OpenTestSystem::OtxDiagManager::Common::ICommandProcessor * processor);
				void SetClientConnectedHandler(std::function<void(int clientId)> handler);
				void SetClientDisconnectedHandler(std::function<void(int clientId)> handler);
				virtual bool SetLicenseKey(const std::string &licenseKey);
			protected:
				virtual void HandleAsyncResult(const OpenTestSystem::OtxDiagManager::Common::Result&);
				virtual void HandleException(const OpenTestSystem::OtxDiagManager::Common::Exception&);
				virtual void OnClientConnected(int clientId);
				virtual void OnClientDisconnected(int clientId);
				OpenTestSystem::OtxDiagManager::Common::ICommandProcessor * _commandProcessor;
				std::function<void(int clientId)> _clientConnectedHandler;
				std::function<void(int clientId)> _clientDisconnectedHandler;
				bool _isLicenseValid;
				std::string _licenseKey;
			};
		}
	}
}
#endif // OpenTestSystem_OtxDiagManager_Server_Server_H