/*!
 * ShutterDevice.cpp
 *
 * Copyright (c) 2016, NADAL Jean-Baptiste. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA
 * 
 * @Author:  NADAL Jean-Baptiste
 * @Date: 20/05/2016
 *
 */



/*------------------------------- INCLUDES ----------------------------------*/

#include <cstdio>

#include "devices/ShutterDevice.h"


/*!  ----------------------------------------------------------------------------
 *  @fn ShutterDevice
 *
 *  @brief Constructor of the ShutterDevice Object.
 */
ShutterDevice::ShutterDevice (void) : Device()
{
}


/*!  ----------------------------------------------------------------------------
 *  @fn ShutterDevice
 *
 *  @brief Destructor of the Device Object.
 */
ShutterDevice::~ShutterDevice (void)
{
}


/*!  ----------------------------------------------------------------------------
 *  @fn load_from_json
 *
 *  @brief Load ShutterDevice Object From a Json Object.
 */
int ShutterDevice::load_from_json (Json::Value anElem)
{
	fprintf (stderr, "ShutterDevice::load_from_json\n");

	mspeach_name = anElem["speach_name"].asString();

	for (Json::Value& theElement : anElem["data"]) {
		Shutter theShutter;
		if (theShutter.load_from_json (theElement) == 0) {

			mShutter.push_back (theShutter);
		}
	}

	return 0;
}


/*!  ----------------------------------------------------------------------------
 *  @fn to_json
 *
 *  @brief Export ShutterDevice Object as JSON Object.
 */
Json::Value ShutterDevice::to_json (bool bDataOnly)
{
	Json::Value theResult;
	Json::Value data_json(Json::arrayValue);
	std::vector<Shutter>::iterator theShutter_it;

	fprintf (stderr, "ShutterDevice::to_json\n");

	for (theShutter_it = mShutter.begin(); theShutter_it != mShutter.end(); theShutter_it++) {
		
		data_json.append ((*theShutter_it).to_json());
	}

	theResult["speach_name"] = mspeach_name;
	theResult["data"] = data_json;

	if (bDataOnly == true)
		return data_json;
	
	return theResult;
}


/*!  ----------------------------------------------------------------------------
 *  @fn set
 *
 *  @brief set the new Shutter state.
 */
int ShutterDevice::set (Json::Value anElement)
{
	return 0;
}


/*!  ----------------------------------------------------------------------------
 *  @fn set
 *
 *  @brief set the new Shutter state.
 */
int ShutterDevice::set (int anID, bool aState)
{
	return 0;
}
