//--------------------------------------------------------------------------------
// <copyright file="PPPHostProgramSettings.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 the PPPHostProgramSettings class, a serializable entity that
//   configures PPPHostProgram
// </summary>
//
// <owner>Mike Cookson</owner>
//--------------------------------------------------------------------------------

#ifndef __PPPHOSTPROGRAMSETTINGS_H__
#define __PPPHOSTPROGRAMSETTINGS_H__

#include "EventSettings.h"
#include "EventTransceiver.h"
#include "LqrSMACSharedLib.h"
#include "PayloadManagerClientSettings.h"
#include "SCPExecutorSettings.h"
#include <ostream>
#include <string>
#include <boost/serialization/access.hpp>
#include <boost/serialization/nvp.hpp>

class SHARED_LIB_PUBLIC PPPHostProgramSettings
{
public:

	typedef LiquidRobotics::EventLib::EventSettings EventSettings;
	typedef LiquidRobotics::EventLib::EventTransceiver EventTransceiver;
	typedef LiquidRobotics::EventLib::PayloadManagerClientSettings PayloadManagerClientSettings;
	typedef LiquidRobotics::PPPHostLib::SCPExecutorSettings SCPExecutorSettings;
	typedef std::string string;

	PPPHostProgramSettings();
	PPPHostProgramSettings(const PPPHostProgramSettings& other);

	PPPHostProgramSettings& operator=(const PPPHostProgramSettings& other);
	bool operator==(const PPPHostProgramSettings& other) const;

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

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

	bool GetWaitForValidGPS() const;
	void SetWaitForValidGPS(bool newValue);

	const EventSettings& GPSEventSettings() const;
	void GPSEventSettings(EventSettings& newValue);

	const EventSettings& NewFileAvailableEventSettings() const;
	void NewFileAvailableEventSettings(EventSettings& newValue);

	const string& NewFileStorageRoot() const;
	void NewFileStorageRoot(const string& newValue);

	bool UseOriginalFilename() const;
	void UseOriginalFilename(bool newValue);

	const EventTransceiver::Settings& GetEventTransceiverSettings() const;
	void SetEventTransceiverSettings(const EventTransceiver::Settings& newValue);

	const SCPExecutorSettings& GetSCPExecutorSettings() const;
	void SetSCPExecutorSettings(const SCPExecutorSettings& newValue);

	const PayloadManagerClientSettings& GetPMClientSettings() const;
	void SetPMClientSettings(const PayloadManagerClientSettings& newValue);

	// Operations to deserialize from (Load) or serialize to (Save) a
	// storage file; in the case of Load, if the file length is 0, the
	// file is overwritten with some example data
	void Load(const string& fileName);
	void Save(const string& fileName);

private:

	// The serialize function is used by the Boost serialization library
	// to save or load member variables from an Archive object; leaving
	// the function in the header file as a template method allows for
	// various archives to be used.
	friend class boost::serialization::access;

	template<class Archive>
	void serialize(Archive& ar, const unsigned int version)
	{
		ar & BOOST_SERIALIZATION_NVP(serverName);
		ar & BOOST_SERIALIZATION_NVP(serverKind);
		ar & BOOST_SERIALIZATION_NVP(waitForValidGPS);
		ar & BOOST_SERIALIZATION_NVP(gpsEventSettings);
		ar & BOOST_SERIALIZATION_NVP(newFileAvailableEvent);
		ar & BOOST_SERIALIZATION_NVP(newFileStorageRoot);
		ar & BOOST_SERIALIZATION_NVP(useOriginalFilename);
		ar & BOOST_SERIALIZATION_NVP(eventTransceiverSettings);
		ar & BOOST_SERIALIZATION_NVP(scpExecutorSettings);
		ar & BOOST_SERIALIZATION_NVP(pmClientSettings);
	}

	string serverName;								// name of the server
	string serverKind;								// kind of the server
	bool waitForValidGPS;							// if true, waits for GPS event with valid sample before starting
	EventSettings gpsEventSettings;					// settings for GPS event
	EventSettings newFileAvailableEvent;			// settings for new file available event
	string newFileStorageRoot;						// storage area for files waiting for transmission
	bool useOriginalFilename;						// if false, default to existing methodology; if true, use the original filename when sending the data.
	EventTransceiver::Settings eventTransceiverSettings; // the event transceiver instance settings
	SCPExecutorSettings scpExecutorSettings;		// the SCP executor instance settings
	PayloadManagerClientSettings pmClientSettings;	// settings for the payload manager client
};

SHARED_LIB_PUBLIC std::ostream& operator<<(std::ostream& out, const PPPHostProgramSettings& settings);

#endif
