/*
 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef __TIZEN_SYSTEM_BATTERY_MONITOR_H__
#define __TIZEN_SYSTEM_BATTERY_MONITOR_H__

#include <tizen.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @addtogroup  CAPI_SYSTEM_BATTERY_BATTERY_MONITOR_MODULE
 * @{
 */

/**
 * @brief        Enumeration for battery monitor error codes.
 * @since_tizen  5.5
 */
typedef enum {
	BATTERY_MONITOR_ERROR_NONE = TIZEN_ERROR_NONE,                                  /**< Successful */
	BATTERY_MONITOR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,                /**< Out of memory */
	BATTERY_MONITOR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,        /**< Invalid parameter */
	BATTERY_MONITOR_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA,                            /**< Empty data */
	BATTERY_MONITOR_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,        /**< Permission denied */
	BATTERY_MONITOR_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,                /**< Not supported */
	BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND = TIZEN_ERROR_BATTERY_MONITOR | 0x01,    /**< Related record does not exist */
	BATTERY_MONITOR_ERROR_DB_FAILED = TIZEN_ERROR_BATTERY_MONITOR | 0x02,           /**< DB operation failed */
	BATTERY_MONITOR_ERROR_DB_NOT_OPENED = TIZEN_ERROR_BATTERY_MONITOR | 0x03,       /**< DB is not connected */
	BATTERY_MONITOR_ERROR_INTERNAL = TIZEN_ERROR_BATTERY_MONITOR | 0x04             /**< Internal error for generic use */
} battery_monitor_error_e;

/**
 * @brief        Enumeration for battery consuming features.
 * @since_tizen  5.5
 */
typedef enum {
	BATTERY_MONITOR_RESOURCE_ID_BLE = 0,             /**< Bluetooth */
	BATTERY_MONITOR_RESOURCE_ID_WIFI = 1,            /**< Wi-Fi */
	BATTERY_MONITOR_RESOURCE_ID_CPU = 2,             /**< CPU */
	BATTERY_MONITOR_RESOURCE_ID_DISPLAY = 3,         /**< Display */
	BATTERY_MONITOR_RESOURCE_ID_DEVICE_NETWORK = 4,  /**< Device Network */
	BATTERY_MONITOR_RESOURCE_ID_GPS_SENSOR = 5,      /**< GPS Sensor*/
	BATTERY_MONITOR_RESOURCE_ID_MAX,                 /**< Use for iterating over enums only */
} battery_monitor_resource_id_e;

/**
 * @brief        Handle for battery consumption, either total or summary for the selected application.
 * @since_tizen  5.5
 *
 * @see  battery_monitor_get_power_usage_by_app_for_all_resources()
 */
typedef struct battery_monitor_total_consumption_s* battery_usage_data_h;

/**
 * @brief  Destroys the Battery Consumption handle and releases all its resources.
 * @since_tizen  5.5
 *
 * @param[in] result  Battery usage consumption handle for the application
 *
 * @return  @c 0 on success,
 *          otherwise a negative error value
 * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
 * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
 * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
 */
int battery_monitor_battery_usage_data_destroy(battery_usage_data_h result);

/**
 * @brief  Gets the battery consumption in mAh (milli-Ampere hour) for specific resource from available data usage handle.
 * @since_tizen  5.5
 * @privlevel  public
 * @privilege  %http://tizen.org/privilege/systemmonitor
 *
 * @param[in] result  Battery consumption data usage handle for the application
 * @param[in] resource  Identifier of resource type. BLE, WiFi, CPU etc
 * @param[out] usage  Battery consumption in mAh for @a resource
 *
 * @return  @c 0 on success,
 *          otherwise a negative error value
 * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
 * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
 * @retval #BATTERY_MONITOR_ERROR_PERMISSION_DENIED     Permission Denied
 * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
 *
 * @pre call battery_monitor_get_power_usage_by_app_for_all_resources() to get data handle
 */
int battery_monitor_usage_data_get_power_usage_per_resource(battery_usage_data_h result, battery_monitor_resource_id_e resource, double* usage);

/**
 * @brief  Gets the #battery_usage_data_h with battery consumption values in mAh (milli-Ampere hour) by the specified application in custom interval.
 *         Data within the last 7 days can be retrieved.
 * @since_tizen  5.5
 * @privlevel  public
 * @privilege  %http://tizen.org/privilege/systemmonitor
 *
 * @remarks  The @a result handle should be released using battery_monitor_battery_usage_data_destroy().
 *
 * @param[in] appid  Application ID of the application for which battery usage is required
 * @param[in] from Start Time for data in Epoch Time (in seconds)
 * @param[in] to End Time for data in Epoch Time (in seconds)
 * @param[out] result  Battery consumption data handle for the application
 *
 * @return  @c 0 on success,
 *          otherwise a negative error value
 * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
 * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
 * @retval #BATTERY_MONITOR_ERROR_PERMISSION_DENIED     Permission Denied
 * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
 * @retval #BATTERY_MONITOR_ERROR_DB_NOT_OPENED         DB not Opened
 * @retval #BATTERY_MONITOR_ERROR_DB_FAILED             DB operation failed
 * @retval #BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND      Record Not found
 * @retval #BATTERY_MONITOR_ERROR_INTERNAL              Internal Error
 *
 * @see battery_monitor_usage_data_get_power_usage_per_resource()
 */
int battery_monitor_get_power_usage_by_app_for_all_resources(const char* appid, time_t from, time_t to, battery_usage_data_h* result);

/**
 * @brief  Gets the battery consumption in mAh (milli-Ampere hour) for the specific resource for the given application in custom interval.
 *         Data within the last 7 days can be retrieved.
 * @since_tizen  5.5
 * @privlevel  public
 * @privilege  %http://tizen.org/privilege/systemmonitor
 *
 * @param[in] appid  Application ID of the application for which battery usage is required
 * @param[in] resource  Identifier of resource type. BLE, WiFi, CPU etc
 * @param[in] from Start Time for data in Epoch Time (in seconds)
 * @param[in] to End Time for data in Epoch Time (in seconds)
 * @param[out] usage  Battery consumption in mAh for the application
 *
 * @return  @c 0 on success,
 *          otherwise a negative error value
 * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
 * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
 * @retval #BATTERY_MONITOR_ERROR_PERMISSION_DENIED     Permission Denied
 * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
 * @retval #BATTERY_MONITOR_ERROR_DB_NOT_OPENED         DB not Opened
 * @retval #BATTERY_MONITOR_ERROR_DB_FAILED             DB operation failed
 * @retval #BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND      Record Not found
 * @retval #BATTERY_MONITOR_ERROR_INTERNAL              Internal Error
 */
int battery_monitor_get_power_usage_by_app_per_resource(const char* appid, battery_monitor_resource_id_e resource, time_t from, time_t to, double* usage);

/**
 * @brief  Gets the total battery usage in mAh (milli-Ampere hour) by an application for certain time interval. Data within the last 7 days can be retrieved.
 * @details  This will be sum of all battery consumed by resources used by application.
 * @since_tizen  5.5
 * @privlevel  public
 * @privilege  %http://tizen.org/privilege/systemmonitor
 *
 * @param[in] appid  Application ID of the application for which battery usage is required
 * @param[in] from Start Time for data in Epoch Time (in seconds)
 * @param[in] to End Time for data in Epoch Time (in seconds)
 * @param[out] usage  Battery consumption in mAh for the application
 *
 * @return  @c 0 on success,
 *          otherwise a negative error value
 * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
 * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
 * @retval #BATTERY_MONITOR_ERROR_PERMISSION_DENIED     Permission Denied
 * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
 * @retval #BATTERY_MONITOR_ERROR_DB_NOT_OPENED         DB not Opened
 * @retval #BATTERY_MONITOR_ERROR_DB_FAILED             DB operation failed
 * @retval #BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND      Record Not found
 * @retval #BATTERY_MONITOR_ERROR_INTERNAL              Internal Error
 */
int battery_monitor_get_power_usage_by_app(const char* appid, time_t from, time_t to, double* usage);

/**
 * @brief  Gets the battery usage in mAh (milli-Ampere hour) by a resource for certain time interval. Data within the last 7 days can be retrieved.
 * @since_tizen  5.5
 * @privlevel  public
 * @privilege  %http://tizen.org/privilege/systemmonitor
 *
 * @param[in] resource  Resource identifier for which battery usage is requested
 * @param[in] from Start Time for data in Epoch Time (in seconds)
 * @param[in] to End Time for data in Epoch Time (in seconds)
 * @param[out] usage  Battery consumption in mAh (milli-Ampere hour) for resource
 *
 * @return  @c 0 on success,
 *          otherwise a negative error value
 * @retval #BATTERY_MONITOR_ERROR_NONE                  Successful
 * @retval #BATTERY_MONITOR_ERROR_NOT_SUPPORTED         Feature Not Supported
 * @retval #BATTERY_MONITOR_ERROR_PERMISSION_DENIED     Permission Denied
 * @retval #BATTERY_MONITOR_ERROR_INVALID_PARAMETER     Invalid Parameter
 * @retval #BATTERY_MONITOR_ERROR_DB_NOT_OPENED         DB not Opened
 * @retval #BATTERY_MONITOR_ERROR_DB_FAILED             DB operation failed
 * @retval #BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND      Record Not found
 * @retval #BATTERY_MONITOR_ERROR_INTERNAL              Internal Error
 */
int battery_monitor_get_power_usage_by_resource(battery_monitor_resource_id_e resource, time_t from, time_t to, double* usage);

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#endif /* __TIZEN_SYSTEM_BATTERY_MONITOR_H__ */
