#ifndef BLE_SERVICE_H
#define BLE_SERVICE_H

#include "wm_type_def.h"

#ifndef CASE_RETURN_STR
#define CASE_RETURN_STR(const) case const: return #const;
#endif

typedef enum
{
    BLE_SERVICE_MODE_STOPPED = 0x00,
    BLE_SERVICE_MODE_IDLE,
    BLE_SERVICE_MODE_ADVERTISING,
    BLE_SERVICE_MODE_CONNECTED,
    BLE_SERVICE_MODE_INDICATING,
    BLE_SERVICE_MODE_EXITING
} ble_service_state_t;

/**
 * @brief Resturns the corresponding enum name as a string
 * 
 * @param state the enum value 
 * @return const char* the enum name as a string
 */
const char *ble_service_state_2_str(uint8_t state);

/**
 * @brief Configures and starts the BLE service
 * 
 * @return true on success
 * @return false on failure
 */
bool ble_service_start(void);

/**
 * @brief Deinits and stops the BLE service
 * 
 * @return true on success
 * @return false on failure
 */
bool ble_service_stop(void);

/**
 * @brief Asks to update the current connection parameters
 * /!\ A connection should be already active before calling this function. 
 * 
 * @param itvl_min Minimum value for connection interval in 1.25ms units
 * @param itvl_max Maximum value for connection interval in 1.25ms units
 * @param latency Connection latency
 * @param supervision_timeout Supervision timeout in 10ms units
 * @param min_ce_len Minimum length of connection event in 0.625ms units
 * @param max_ce_len Maximum length of connection event in 0.625ms units
 * @return true 
 * @return false 
 */
bool ble_service_update_connection_parameters(
    uint16_t itvl_min,
    uint16_t itvl_max,
    uint16_t latency,
    uint16_t supervision_timeout,
    uint16_t min_ce_len,
    uint16_t max_ce_len);

/**
 * @brief Sends a custom notification with the provided payload of size length
 * 
 * @param data the data to send in the notification
 * @param length the lenght in byte of the data to send
 * @return true on success
 * @return false on failure
 */
bool ble_service_send_custom_notification(const uint8_t *data, uint16_t length);

/**
 * @brief Requests a MTU (Maximum Transmission Unit) update in order to hopefully, get something bigger than 20 bytes ...
 * 
 * @return true on success
 * @return false on failure
 */
bool ble_service_request_mtu_exchange(void);

#endif //BLE_APP_H