//-------------------------------------------------------------------------------------------------
// <copyright file="LWControllerSettings.h" company="LiquidRobotics">
//  Copyright (c) Liquid Robotics Corporation, confidential and proprietary.  All rights reserved. 
// </copyright>
//
// <summary>
//	Declarations for LWControllerSettings class, a boost-serializable entity
//	representing the configurable settings for the controller class.
// </summary>
//
// <owner>Mike Cookson</owner>
//-------------------------------------------------------------------------------------------------

#ifndef __LWControllerSettings_h__
#define __LWControllerSettings_h__

#include "LqrSMACSerialListenerSettings.h"
#include "LqrSMACSerialPortSettings.h"
#include "LqrSMACSharedLib.h"
#include <map>
#include <string>
#include <boost/serialization/access.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/version.hpp>

namespace LiquidRobotics {
namespace LuaWrapper {

class SHARED_LIB_PUBLIC LWControllerSettings
{
public:

	typedef LiquidRobotics::SMACFramework::SerialListenerSettings SerialListenerSettings;
	typedef LiquidRobotics::SMACFramework::SerialPortSettings SerialPortSettings;
	typedef std::string string;

	struct SerialConfig
	{
		SerialListenerSettings listenerSettings;
		SerialPortSettings portSettings;

		friend class boost::serialization::access;

		template<class Archive>
		void serialize(Archive & ar, const unsigned int version)
		{
			ar & BOOST_SERIALIZATION_NVP(listenerSettings);
			ar & BOOST_SERIALIZATION_NVP(portSettings);
		}
	};

	typedef std::map<string,SerialConfig> SerialConfigMap;

	LWControllerSettings();
	LWControllerSettings(const LWControllerSettings& rhs);

	LWControllerSettings& operator=(const LWControllerSettings& rhs);

	const string& GetDefaultFormatter() const;
	void SetDefaultFormatter(const string& newValue);

	const SerialConfig& GetSerialConfig(const string& configName) const;
	const SerialConfigMap& GetSerialConfigMap() const;
	bool HasSerialConfig(const string& configName) const;
	void SetSerialConfigMap(const SerialConfigMap& newValue);

	void Load(const string& fileName, bool withMD5 = false);
	void Save(const string& fileName, bool withMD5 = false) const;

private:

	friend class boost::serialization::access;

	template<class Archive>
	void load(Archive & ar, const unsigned int version)
	{
		if (version >= 2)
			ar & BOOST_SERIALIZATION_NVP(defaultFormatter);

		ar & BOOST_SERIALIZATION_NVP(serialConfigMap);
	}

	template<class Archive>
	void save(Archive & ar, const unsigned int version) const
	{
		ar & BOOST_SERIALIZATION_NVP(defaultFormatter);
		ar & BOOST_SERIALIZATION_NVP(serialConfigMap);
	}

	BOOST_SERIALIZATION_SPLIT_MEMBER()

	string defaultFormatter;
	SerialConfigMap serialConfigMap;
};

}
}

BOOST_CLASS_VERSION(LiquidRobotics::LuaWrapper::LWControllerSettings, 2)
BOOST_CLASS_VERSION(LiquidRobotics::LuaWrapper::LWControllerSettings::SerialConfig, 1)

#endif
