#include "include.h"
#include "api.h"

extern const uint8_t   sdp_spp_service_record[];
extern const uint8_t   sdp_spp_dueros_service_record[];
extern const uint8_t   sdp_spp_proc_test_service_record[];
extern const uint8_t   sdp_spp_dueros_ota_service_record[];
extern const uint8_t   sdp_hid_keyboard_service_record[];
extern const uint8_t   sdp_hid_consumer_service_record[];
extern const uint8_t   sdp_hid_tscreen_service_record[];
extern const uint8_t   sdp_hid_tscreen_ext_service_record[];
extern const uint8_t   sdp_devic_id_service_record[];

typedef struct {
    void    *item;
    uint32_t service_record_handle;
    uint8_t *service_record;
} service_record_item_t;

#if DUEROS_SUPPORT_EN
service_record_item_t spp_sdp_record_item = {
    .service_record_handle  = 0x50010001,
    .service_record         = (uint8_t *)sdp_spp_dueros_service_record,
};

service_record_item_t spp_proc_test_sdp_record_item = {
    .service_record_handle  = 0x50010002,
    .service_record         = (uint8_t *)sdp_spp_proc_test_service_record,
};

service_record_item_t spp_dueros_ota_sdp_record_item = {
    .service_record_handle  = 0x50010003,
    .service_record         = (uint8_t *)sdp_spp_dueros_ota_service_record,
};
#elif BT_SPP_EN
service_record_item_t spp_sdp_record_item = {
    .service_record_handle  = 0x00010001,
    .service_record         = (uint8_t *)sdp_spp_service_record,
};
#endif


#if BT_HID_EN
service_record_item_t hid_sdp_record_item = {
    .service_record_handle  = 0x00010006,
#if (BT_HID_TYPE == 0)
    .service_record         = (uint8_t *)sdp_hid_consumer_service_record,
#elif (BT_HID_TYPE == 1)
    .service_record         = (uint8_t *)sdp_hid_keyboard_service_record,
#elif (BT_HID_TYPE == 2)
    .service_record         = (uint8_t *)sdp_hid_tscreen_service_record,
#else
    .service_record         = ...
#endif
};

service_record_item_t device_id_sdp_record_item = {
    .service_record_handle  = 0x00010007,
    .service_record         = (uint8_t *)sdp_devic_id_service_record,
};
#endif // BT_HID_EN

void bt_init_lib(void)
{
    uint32_t profile = cfg_bt_support_profile;
#if BT_SPP_EN
    if (profile & PROF_SPP) {
#if DUEROS_SUPPORT_EN
		spp_support_mul_server(1);
#endif
        spp_init();
        sdp_add_service(&spp_sdp_record_item);
#if DUEROS_SUPPORT_EN
		sdp_add_service(&spp_proc_test_sdp_record_item);
		sdp_add_service(&spp_dueros_ota_sdp_record_item);
#endif
    }
#endif

#if BT_HID_EN
    if (profile & PROF_HID) {
        hid_device_init();
        sdp_add_service(&hid_sdp_record_item);
        sdp_add_service(&device_id_sdp_record_item);
    }
#endif
}
