//------------------------------------------------------------------------------
// <copyright file="SCPExecutorSettings.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 SCPExecutorSettings class, a serializable entity that
//   contains the settings for the SCPExecutor class.
// </summary>
//
// <owner>Mike Cookson</owner>
//------------------------------------------------------------------------------

#ifndef __SCPEXECUTORSETTINGS_H__
#define __SCPEXECUTORSETTINGS_H__

#include "LqrSMACSharedLib.h"
#include "PPPHostSettings.h"
#include <string>
#include <boost/serialization/access.hpp>
#include <boost/serialization/nvp.hpp>

namespace LiquidRobotics {
namespace PPPHostLib {

class SHARED_LIB_PUBLIC SCPExecutorSettings
{
public:

	typedef std::string string;

	SCPExecutorSettings();
	SCPExecutorSettings(const SCPExecutorSettings& other);

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

	float GetCallInterval() const;
	void SetCallInterval(const float newValue);

	const string& GetSCPVerb() const;
	void SetSCPVerb(const string& newValue);

	const string& GetRunVerb() const;
	void SetRunVerb(const string& newValue);

	const string& GetNextCallIntervalVerb() const;
	void SetNextCallIntervalVerb(const string& newValue);

	const string& GetModemSerialNumberFilename() const;
	void SetNextCallIntervalFilename(const string& newValue);

	const string& GetModemSimCardFilename() const;
	void SetModemSimCardFilename(const string& newValue);

	const PPPHostSettings& GetPPPHostSettings() const;
	void SetPPPHostSettings(const PPPHostSettings& newValue);

	unsigned GetQueueCapacity() const;
	void SetQueueCapacity(unsigned 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(callInInterval);
		ar & BOOST_SERIALIZATION_NVP(scpVerb);
		ar & BOOST_SERIALIZATION_NVP(runVerb);
		ar & BOOST_SERIALIZATION_NVP(queueCapacity);
		ar & BOOST_SERIALIZATION_NVP(nextCallIntervalVerb);
		ar & BOOST_SERIALIZATION_NVP(modemSerialNumberFilename);
		ar & BOOST_SERIALIZATION_NVP(modemSimCardFilename);
		ar & BOOST_SERIALIZATION_NVP(pppSettings);

		CheckValues();
	}

	void CheckValues() const;

	float callInInterval;							// the number of seconds to wait between calls (including fraction, <= 0 to disable call-in's)
	string scpVerb;									// the command to run first after PPP session established
	string runVerb;									// the command to run second if the first command succeeds
	unsigned queueCapacity;							// the size of the message queue used internally by SCP Executor
	string nextCallIntervalVerb;					// if not blank, the command that will return a string for the next call-in interval or blank if use "callInInterval" setting
	string modemSerialNumberFilename;				// if not blank, the name of the file that will be set to the modem serial number upon PPP connection
	string modemSimCardFilename;					// if not blank, the name of the file that will be set to the modem SIM card number upon PPP connection
	PPPHostSettings pppSettings;					// the PPP instance settings
};

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

}
}

#endif
