
#ifndef ble_needlite_H__
#define ble_needlite_H__

#include <stdint.h>
#include <stdbool.h>
#include "ble.h"
#include "ble_srv_common.h"

#define HELMETALERT_UUID_BASE {0xFC, 0x6F, 0x20, 0x26, 0xF4, 0x58, 0x39, 0x8B, 0x8A, 0x41, 0x89, 0xE4, 0x00, 0x00, 0xC1, 0xDD}
#define HELMETALERT_UUID_SERVICE           0xDA78

#define HELMETALERT_UUID_BUTTON_CHAR       0x1524
#define HELMETALERT_UUID_LED_CHAR          0x1525
#define HELMETALERT_UUID_DISPLAYNAME_CHAR  0x1526
#define HELMETALERT_UUID_PROXIMITY_CHAR    0x1527
#define HELMETALERT_UUID_EVENT_CMD_CHAR    0x1528
#define HELMETALERT_UUID_EVENT_DATA_CHAR   0x1529

#define HELMETALERT_UUID_TEST 0xFF

typedef enum {
    ble_needlite_EVT_NOTIFICATION_ENABLED,                             /**< Battery value notification enabled event. */
    ble_needlite_EVT_NOTIFICATION_DISABLED                             /**< Battery value notification disabled event. */
} ble_needlite_evt_type_t;

typedef struct {
    ble_needlite_evt_type_t evt_type;                                  /**< Type of event. */
} ble_needlite_evt_t;

typedef struct ble_needlite_s ble_needlite_t;
typedef void (*ble_needlite_evt_handler_t) (ble_needlite_t * p_needlite, uint8_t led_state);

typedef struct {
    ble_needlite_evt_handler_t      led_write_handler;
    bool                            support_notification;
    bool                            reliable_write;
    ble_srv_report_ref_t *          p_report_ref;
    uint8_t                         initial_led_level;
    uint8_t                         initial_on_off_state;
    ble_srv_cccd_security_mode_t    led_level_char_attr_md;
    ble_gap_conn_sec_mode_t         led_level_report_read_perm;
} ble_needlite_init_t;

typedef struct ble_needlite_s {
    ble_needlite_evt_handler_t  led_write_handler;
    uint16_t                    service_handle;
    ble_gatts_char_handles_t    led_brightness_handles;
    ble_gatts_char_handles_t    led_state_handles;
    ble_gatts_char_handles_t    displayname_handles;
    ble_gatts_char_handles_t    proximity_handles;
    
    //ble_gatts_char_handles_t    event_handles;
    ble_gatts_char_handles_t    event_cmd_handles;
    ble_gatts_char_handles_t    event_data_handles;

    uint16_t                    report_ref_handle;
    uint8_t                     sv_uuid_type;
    uint8_t                     ch1_uuid_type;
    uint8_t                     ch2_uuid_type;
    uint16_t                    conn_handle;
    bool                        is_notification_supported;
} ble_needlite_t;


uint32_t ble_needlite_init(ble_needlite_t * p_needlite, const ble_needlite_init_t * p_needlite_init);

uint32_t ble_lbs_brightness_change(ble_needlite_t * p_lbs, uint8_t led_level);

uint32_t ble_lbs_onoff_change(ble_needlite_t * p_lbs, uint8_t button_state);

uint32_t ble_lbs_proximity_change(ble_needlite_t * p_lbs, uint8_t proximity);

uint32_t ble_lbs_event_data_send(ble_needlite_t * p_lbs, event_log_packet_t * packet);

void ble_needlite_on_ble_evt(ble_needlite_t * p_needlite, ble_evt_t * p_ble_evt);



#endif // ble_needlite_H__

/** @} */
