/*!
 * capabilities_shutters.cpp
 *
 * Copyright (c) 2015-2018, 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: 24/03/2015
 *
 */

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

extern "C" {
#include <libubox/blobmsg_json.h>
}

#include <json-c/json.h>

#include "devices/devices-manager.h"

#include "domo.h"

#include "capabilities_shutters_model.h"

namespace
{

using namespace UBus;

static ObjectType gCapabilitiesShuttersModelUbus_types(
	"shutters",
	Method("get", UBUS_CPP(CapabilitiesShuttersModel, get)),
	Method("delete", UBUS_CPP(CapabilitiesShuttersModel, del)),
	Method("put", UBUS_CPP(CapabilitiesShuttersModel, put)),
	Method("post", UBUS_CPP(CapabilitiesShuttersModel, post)),

	Method("open", UBUS_CPP(CapabilitiesShuttersModel, open)),
	Method("close", UBUS_CPP(CapabilitiesShuttersModel, close)),

	Method("up", UBUS_CPP(CapabilitiesShuttersModel, up)),
	Method("down", UBUS_CPP(CapabilitiesShuttersModel, down)),

	Method("position", UBUS_CPP(CapabilitiesShuttersModel, position)));
}

/*!  ----------------------------------------------------------------------------
 *  @fn CapabilitiesShuttersModel
 *
 *  @brief Constructor of the UBus Mixer Volume.
 */
CapabilitiesShuttersModel::CapabilitiesShuttersModel(DevicesManager *a_device_manager) : UBusObject(gCapabilitiesShuttersModelUbus_types, "domo.capabilities.shutters"),
																						 m_devices_manager(a_device_manager)
{
}

/*!  ----------------------------------------------------------------------------
 *  @fn ~CapabilitiesShuttersModel
 *
 *  @brief Destructor of the UBus Mixer Volume.
 */
CapabilitiesShuttersModel::~CapabilitiesShuttersModel(void)
{
}

/*!  ----------------------------------------------------------------------------
 *  @fn get
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::get(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *)
{
	int the_result;
	struct blob_buf the_buf = {0};

	blob_buf_init(&the_buf, 0);

	blobmsg_add_json_from_string(&the_buf, m_devices_manager->get(kShutterEntry).c_str());

	the_result = ubus_send_reply(a_ctx, a_req, the_buf.head);

	blob_buf_free(&the_buf);

	return the_result;
}

/*!  ----------------------------------------------------------------------------
 *  @fn del
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::del(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
{
	int the_result = 0;

	return the_result;
}

/*!  ----------------------------------------------------------------------------
 *  @fn put
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::put(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
{
	int the_result = 0;

	return the_result;
}

/*!  ----------------------------------------------------------------------------
 *  @fn post
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::post(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
{
	int the_result = 0;

	return the_result;
}

/*!  ----------------------------------------------------------------------------
 *  @fn open
 *
 *  @brief Open the Shutter
 */
int CapabilitiesShuttersModel::open(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
{
	int the_result = 0;
	printf("Open the Shutter\n");
	return the_result;
}

/*!  ----------------------------------------------------------------------------
 *  @fn close
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::close(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
{
	int the_result = 0;
	printf("Close the Shutter\n");
	return the_result;
}

/*!  ----------------------------------------------------------------------------
 *  @fn up
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::up(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
{
	int the_result = 0;
	printf("Up the Shutter\n");
	return the_result;
}

/*!  ----------------------------------------------------------------------------
 *  @fn down
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::down(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
{
	int the_result = 0;
	printf("Down the Shutter\n");
	return the_result;
}

/*!  ----------------------------------------------------------------------------
 *  @fn position
 *
 *  @brief Get the List of the Capabilities.
 */
int CapabilitiesShuttersModel::position(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
{
	int the_result = 0;
	printf("Position the Shutter\n");
	return the_result;
}
