//------------------------------------------------------------------------------
// <copyright file="SSQControllerSettings.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 SSQControllerSettings, a serializable entity that holds the
//  settings for the SSQ sensor controller class.
// </summary>
//
// <owner>Mike Cookson</owner>
//------------------------------------------------------------------------------

#ifndef __SSQControllerSettings_h__
#define __SSQControllerSettings_h__

#include "LqrSMACSharedLib.h"
#include "LqrSMACBooleanParser.h"
#include "SSQCommunicatorSettings.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 SimpleSBDQueue {

class SHARED_LIB_PUBLIC SSQControllerSettings
{
public:

	typedef std::string string;

	SSQControllerSettings();
	SSQControllerSettings(const SSQControllerSettings& rhs);

	SSQControllerSettings& operator=(const SSQControllerSettings& rhs);

    bool GetAutoStart() const;
    void SetAutoStart(bool newValue);

    bool GetConcatenateSentPackets() const;
    void SetConcatenateSentPackets(bool newValue);

    const SSQCommunicatorSettings& GetCommunicatorSettings() const;
    void SetCommunicatorSettings(const SSQCommunicatorSettings& 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)
	{
        using namespace LiquidRobotics::SMACFramework::BooleanParser;

        load_boolean_from_archive(ar, autoStart, "autoStart");

        if (version >= 2)
        	load_boolean_from_archive(ar, concatenateSentPackets, "concatenateSentPackets");

		ar >> BOOST_SERIALIZATION_NVP(communicatorSettings);
	}

	template<class Archive>
	void save(Archive & ar, const unsigned int version) const
	{
        using namespace LiquidRobotics::SMACFramework::BooleanParser;

        save_boolean_to_archive(ar, autoStart, "autoStart");
        save_boolean_to_archive(ar, concatenateSentPackets, "concatenateSentPackets");
		ar << BOOST_SERIALIZATION_NVP(communicatorSettings);
	}

	BOOST_SERIALIZATION_SPLIT_MEMBER()

    bool autoStart;
	bool concatenateSentPackets;
    SSQCommunicatorSettings communicatorSettings;
};

}
}

BOOST_CLASS_VERSION(LiquidRobotics::SimpleSBDQueue::SSQControllerSettings, 2)

#endif
