//----------------------------------------------------------------------------------
// <copyright file="PayloadInterfaceSettings.h" company="LiquidRobotics">
//
// Copyright (c) 2014 Liquid Robotics, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// This software is associated with a release.  Liquid Robotics makes no
// representation that the design, interfaces or component distribution will
// remain unchanged in future releases.
//
// </copyright>
//
// <summary>
//   Declarations for PayloadInterfaceSettings, a serializable entity that holds the
//   configuration settings for PayloadInterface
// </summary>
//
// <owner>Mike Cookson</owner>
//----------------------------------------------------------------------------------

#ifndef __PAYLOADINTERFACELIB_PAYLOADINTERFACESETTINGS_H__
#define __PAYLOADINTERFACELIB_PAYLOADINTERFACESETTINGS_H__

#include <ostream>
#include <string>
#include <boost/serialization/access.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/version.hpp>
#include "PayloadInterfaceController_Config.h"
#include "LqrSMACBooleanParser.h"
#include "LqrSMACStdOutLoggerSettings.h"
#include "LqrSMACSerialPortSettings.h"
#include "LqrSMACSharedLib.h"
#include "StorageController.h"
#include "SV3NetInterfaceSettings.h"
#include "TelemetryBuffer.h"

namespace LiquidRobotics {
namespace PayloadInterface {

class SHARED_LIB_PUBLIC PayloadInterfaceSettings
{
public:

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

	PayloadInterfaceSettings();
	virtual ~PayloadInterfaceSettings();

	const StdOutLoggerSettings& GetLoggerSettings() const;
	void SetLoggerSettings(const StdOutLoggerSettings& newValue);

	bool GetSV3Enabled() const									{ return sv3Enabled; }
	void SetSV3Enabled(bool newValue);

	const SerialPortSettings& GetPortSettings() const			{ return serialPortSettings; }
	void SetPortSettings(const SerialPortSettings& newValue);

	const SV3NetInterfaceSettings& GetSV3NetInterfaceSettings() const { return sv3NetInterfaceSettings; }
	void SetSV3NetInterfaceSettings(SV3NetInterfaceSettings& newValue);

	const StorageController::Config& GetSCSettings() const		{ return scSettings; }
	void SetSCSettings(const StorageController::Config& newValue);

	const PayloadInterfaceController_Config& GetControllerSettings() const { return picSettings; }
	void SetControllerSettings(const PayloadInterfaceController_Config& newValue);

	const string& GetServerName() const;
	void SetServerName(const string& newValue);

	const string& GetServerKind() const;
	void SetServerKind(const string& newValue);

	void Load(const string& fileName);
	void Save(const string& fileName);

private:

	friend class boost::serialization::access;

	template<class Archive>
	void load(Archive & ar, const unsigned int version)
	{
		ar & BOOST_SERIALIZATION_NVP(loggerSettings);
		if (version >= 2)
			LiquidRobotics::SMACFramework::BooleanParser::load_boolean_from_archive(ar, sv3Enabled, "sv3Enabled");
		else
			sv3Enabled = false;
		ar & BOOST_SERIALIZATION_NVP(serialPortSettings);
		if (version >= 2) ar & BOOST_SERIALIZATION_NVP(sv3NetInterfaceSettings);
		ar & BOOST_SERIALIZATION_NVP(scSettings);
		ar & BOOST_SERIALIZATION_NVP(picSettings);
		ar & BOOST_SERIALIZATION_NVP(serverName);
		ar & BOOST_SERIALIZATION_NVP(serverKind);
	}

	template<class Archive>
	void save(Archive & ar, const unsigned int version) const
	{
		ar & BOOST_SERIALIZATION_NVP(loggerSettings);
		if (version >= 2)
			LiquidRobotics::SMACFramework::BooleanParser::save_boolean_to_archive(ar, sv3Enabled, "sv3Enabled");
		ar & BOOST_SERIALIZATION_NVP(serialPortSettings);
		if (version >= 2) ar & BOOST_SERIALIZATION_NVP(sv3NetInterfaceSettings);
		ar & BOOST_SERIALIZATION_NVP(scSettings);
		ar & BOOST_SERIALIZATION_NVP(picSettings);
		ar & BOOST_SERIALIZATION_NVP(serverName);
		ar & BOOST_SERIALIZATION_NVP(serverKind);
	}

	BOOST_SERIALIZATION_SPLIT_MEMBER()

	StdOutLoggerSettings loggerSettings;
	bool sv3Enabled;
	SerialPortSettings serialPortSettings;
	SV3NetInterfaceSettings sv3NetInterfaceSettings;
	StorageController::Config scSettings;
	PayloadInterfaceController_Config picSettings;
	string serverName;
	string serverKind;
};

SHARED_LIB_PUBLIC std::ostream& operator<<(std::ostream& stm, const PayloadInterfaceSettings& settings);

}
}

BOOST_CLASS_VERSION(LiquidRobotics::PayloadInterface::PayloadInterfaceSettings, 2)

#endif
