//--------------------------------------------------------------------------------------
// <copyright file="DataRecorderSettings.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 DataRecorderSettings class, an entity that holds the configurations
//  for the DataRecorder process
// </summary>
//
// <owner>Raj Jha</owner>
//--------------------------------------------------------------------------------------

#ifndef __DATARECORDERSETTINGS_H__
#define __DATARECORDERSETTINGS_H__

#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/version.hpp>
#include "EventTransceiver.h"
#include "LqrSMACSerialPort.h"
#include "LqrSMACSerialPortSettings.h"
#include "LqrSMACSerialListenerSettings.h"
#include "LqrSMACSharedLib.h"
#include "PayloadManagerClientSettings.h"
#include "EventSettings.h"

namespace LiquidRobotics {
namespace DataRecorder {

class DataRecorderSettings
{
public:

	typedef std::string string;
	typedef LiquidRobotics::EventLib::EventSettings EventSettings;
	typedef LiquidRobotics::EventLib::EventTransceiver::Settings EventTransceiverSettings;
	typedef LiquidRobotics::EventLib::PayloadManagerClientSettings PayloadManagerClientSettings;
	typedef LiquidRobotics::SMACFramework::ISerialPort ISerialPort;
	typedef ISerialPort::TimeSpan TimeSpan;
	typedef LiquidRobotics::SMACFramework::SerialPortSettings SerialPortSettings;
	typedef LiquidRobotics::SMACFramework::SerialListenerSettings SerialListenerSettings;

	DataRecorderSettings();
	virtual ~DataRecorderSettings();

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

	const string& GetServerKind() const			{ return serverKind; }
	void SetServerKind(const string& newValue)	{ serverKind = newValue; }

	const SerialPortSettings& GetSerialPortSettings() const			{ return serialPortSettings; }
	void SetSerialPortSettings(const SerialPortSettings& newValue)	{ serialPortSettings = newValue; }

	const SerialListenerSettings& GetSerialListenerSettings() const			{ return serialListenerSettings; }
	void SetSerialListenerSettings(const SerialListenerSettings& newValue)	{ serialListenerSettings = newValue; }

	const string& GetOutFileName() const			{ return outFileName; }
	void SetOutFileName(const string& newValue)		{ outFileName = newValue; }

	const string& GetPowerOnVerb() const			{ return powerOnVerb; }
	void SetPowerOnVerb(const string& newValue)		{ powerOnVerb = newValue; }

	const string& GetPowerOffVerb() const			{ return powerOffVerb; }
	void SetPowerOffVerb(const string& newValue)	{ powerOffVerb = newValue; }

	unsigned GetOutputFormat() const				{ return outputFormat; }
	void SetOutputFormat(unsigned newValue)			{ outputFormat = newValue; }

	const EventSettings& GetCommandCompleteEventSettings() const;
	void SetCommandCompleteEventSettings(const EventSettings& newValue);

	const EventSettings& GetGPSEventSettings() const;
	void SetGPSEventSettings(const EventSettings& newValue);

	const EventSettings& GetTelemetryChangedEventSettings() const;
	void SetTelemetryChangedEventSettings(const EventSettings& newValue);

	const EventTransceiverSettings& GetEventTransceiverSettings() const;
	void SetEventTransceiverSettings(const EventTransceiverSettings& newValue);

	const PayloadManagerClientSettings& GetPayloadManagerClientSettings() const;
	void SetPayloadManagerClientSettings(const PayloadManagerClientSettings& newValue);

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

private:

	friend class boost::serialization::access;

	template<class Archive>
	void load(Archive & ar, const unsigned int version)
	{
		ar & BOOST_SERIALIZATION_NVP(serverName);
		ar & BOOST_SERIALIZATION_NVP(serverKind);
		ar & BOOST_SERIALIZATION_NVP(serialPortSettings);
		ar & BOOST_SERIALIZATION_NVP(serialListenerSettings);
		ar & BOOST_SERIALIZATION_NVP(outFileName);
		ar & BOOST_SERIALIZATION_NVP(powerOnVerb);
		ar & BOOST_SERIALIZATION_NVP(powerOffVerb);

		if (version >= 2)
			ar & BOOST_SERIALIZATION_NVP(outputFormat);

		ar & BOOST_SERIALIZATION_NVP(commandCompleteEventSettings);
		ar & BOOST_SERIALIZATION_NVP(gpsEventSettings);
		ar & BOOST_SERIALIZATION_NVP(telemetryChangedEventSettings);
		ar & BOOST_SERIALIZATION_NVP(eventTransceiverSettings);
		ar & BOOST_SERIALIZATION_NVP(payloadManagerClientSettings);
	}

	template<class Archive>
	void save(Archive & ar, const unsigned int version) const
	{
		ar & BOOST_SERIALIZATION_NVP(serverName);
		ar & BOOST_SERIALIZATION_NVP(serverKind);
		ar & BOOST_SERIALIZATION_NVP(serialPortSettings);
		ar & BOOST_SERIALIZATION_NVP(serialListenerSettings);
		ar & BOOST_SERIALIZATION_NVP(outFileName);
		ar & BOOST_SERIALIZATION_NVP(powerOnVerb);
		ar & BOOST_SERIALIZATION_NVP(powerOffVerb);
		ar & BOOST_SERIALIZATION_NVP(outputFormat);
		ar & BOOST_SERIALIZATION_NVP(commandCompleteEventSettings);
		ar & BOOST_SERIALIZATION_NVP(gpsEventSettings);
		ar & BOOST_SERIALIZATION_NVP(telemetryChangedEventSettings);
		ar & BOOST_SERIALIZATION_NVP(eventTransceiverSettings);
		ar & BOOST_SERIALIZATION_NVP(payloadManagerClientSettings);
	}

	BOOST_SERIALIZATION_SPLIT_MEMBER()

	string serverName;
	string serverKind;
	SerialPortSettings serialPortSettings;
	SerialListenerSettings serialListenerSettings;		// configuration for SerialListener associated with serial port
	string outFileName;
	string powerOnVerb;
	string powerOffVerb;
	unsigned outputFormat;
	EventSettings commandCompleteEventSettings;
	EventSettings gpsEventSettings;
	EventSettings telemetryChangedEventSettings;
	EventTransceiverSettings eventTransceiverSettings;
	PayloadManagerClientSettings payloadManagerClientSettings;
};

} // namespace LiquidRobotics
} // namespace DataRecorder

BOOST_CLASS_VERSION(LiquidRobotics::DataRecorder::DataRecorderSettings, 2)

#endif
