#ifndef _TSL_API_H__
#define _TSL_API_H__
#include "lite-cjson.h"
#include "kk_tsl_common.h"
#include "../../midware/dm/iotx_dm.h"



#define KK_MSG_KEY_ID                   "msgId"
#define KK_MSG_KEY_VERSION              "version"
#define KK_MSG_KEY_METHOD               "method"
#define KK_MSG_KEY_PARAMS               "params"
#define KK_MSG_KEY_CODE                 "code"
#define KK_MSG_KEY_DATA                 "data"
#define KK_MSG_KEY_MESSAGE              "message"


/*typedef enum {
    IOTX_DM_ERR_CODE_SUCCESS              = 200,
    IOTX_DM_ERR_CODE_REQUEST_ERROR        = 400,
    IOTX_DM_ERR_CODE_REQUEST_PARAMS_ERROR = 460,
    IOTX_DM_ERR_CODE_REQUEST_TOO_MANY     = 429,
    IOTX_DM_ERR_CODE_NO_ACTIVE_SESSION    = 520,
    IOTX_DM_ERR_CODE_TIMEOUT              = 100000
} iotx_dm_error_code_t;*/

typedef struct {
    const char *uri;
    unsigned char *payload;
    unsigned int payload_len;
    void *context;
} kk_msg_source_t;

typedef struct {
    const char *uri_name;
} kk_msg_dest_t;

typedef struct {
    lite_cjson_t id;
    lite_cjson_t version;
    lite_cjson_t method;
    lite_cjson_t params;
} kk_msg_request_payload_t;

typedef struct {
    lite_cjson_t id;
    lite_cjson_t code;
    lite_cjson_t data;
    lite_cjson_t message;
} kk_msg_response_payload_t;



typedef enum {
	kk_tsl_set_property_value = 0,
	kk_tsl_set_event_output_value,
	kk_tsl_set_service_output_value,
	kk_tsl_set_number,
} kk_tsl_set_t;
typedef enum {
	kk_tsl_get_property_value = 0,
	kk_tsl_get_event_output_value,
	kk_tsl_get_service_input_value,
	kk_tsl_get_service_output_value,
	kk_tsl_get_number,
} kk_tsl_get_t;

typedef struct {
	kk_tsl_t * shadow;
	lite_cjson_item_t *lite;
} dm_api_property_t;
extern int kk_tsl_api_init(void);
extern int kk_tsl_set_value(kk_tsl_set_t set, kk_tsl_t *dev_shadow, const char *identifier, \
                                       const void *value, \
                                       const char *value_str);
extern int kk_tsl_get_value(kk_tsl_get_t method_get, kk_tsl_t * dev_shadow, const char *identifier, \
                                       void *value, \
                                       char **value_str);

extern int kk_msg_uri_parse_pkdn(_IN_ char *uri, _IN_ int uri_len, _IN_ int start_deli, _IN_ int end_deli, \
                          _OU_ char productType[PRODUCT_TYPE_MAXLEN], _OU_ char deviceCode[DEVICE_CODE_MAXLEN]);

extern char* kk_tsl_get_post_property_str(kk_tsl_t		   *dev_shadow, const char *property_identifier);
extern char* kk_tsl_get_post_event_str(_IN_ kk_tsl_t *dev_shadow, _IN_ char *identifier, _IN_ int identifier_len);
extern char * kk_tsl_get_post_service_str(kk_tsl_t *dev_shadow, const char *service_identifier);
int kk_tsl_property_set_by_shadow(kk_tsl_t* dev_shadow, const char *payload, unsigned int payload_len);
int kk_tsl_get_property_data(_IN_ kk_tsl_t *shadow, _IN_ char *key, _IN_ int key_len, _OU_ void **data);
int dm_tsl_get_event_output_data(_IN_ kk_tsl_t *shadow, _IN_ char *key, _IN_ int key_len, _OU_ void **data);
int dm_tls_set_event_output_value(_IN_ kk_tsl_t *shadow, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
                                  _IN_ int value_len);
int dm_tsl_get_service_input_output_data(_IN_ kk_tsl_data_target_e type, _IN_ kk_tsl_t *shadow, _IN_ char *key,
        _IN_ int key_len, _OU_ void **data);
int dm_tsl_set_service_input_output_value(_IN_ kk_tsl_data_target_e type, _IN_ kk_tsl_t *shadow, _IN_ char *key,
        _IN_ int key_len, _IN_ void *value, _IN_ int value_len);
int dm_tsl_set_property_value(_IN_ kk_tsl_t *shadow, _IN_ char *key, _IN_ int key_len, _IN_ void *value,
                              _IN_ int value_len);
int kk_tsl_get_data_type(_IN_ void *data, _OU_ kk_tsl_data_type_e *type);  
int kk_tsl_get_property_type(_IN_ kk_tsl_t *dev_shadow, _IN_ char *key);   
int kk_tsl_get_event_by_identifier(_IN_ kk_tsl_t *dev_shadow, _IN_ char *identifier, _OU_ void **event);
int kk_tsl_get_event_method(_IN_ void *event, _OU_ char **method);   
int kk_tsl_get_service_by_identifier(_IN_ kk_tsl_t *dev_shadow, _IN_ char *identifier, _OU_ void **service);       
int kk_tsl_get_service_method(_IN_ void *service, _OU_ char **method);                                                          
#endif
