#ifndef _IKONKE_CLUSTER_H_
#define _IKONKE_CLUSTER_H_


#include "tl_common.h"
#include "ikk-module-def.h"
#include "zb_api.h"
#include "zcl_include.h"
#include "zcl.h"
#include "ikk-network.h"

typedef struct {
	uint8_t endpoint;
	uint8_t onOffValue;
	bool isMultiContorl; //whether multi-control, used to judge whether send response or multi-control
	bool isSendResponse;
	addrExt_t maskEui64Addr;
	uint8_t dest_endpoint;
}ZclOnOffControlInfoSt;

typedef enum{ EOOS_OFF = 0, EOOS_ON, EOOS_UNKNOW }OnOffStatusEnum;
typedef enum{ EOOC_OFF = 0, EOOC_ON, EOOC_TOGGLE, EOOC_UNKNOW }OnOffCtrlEnum;

#define RESET_ENDPOINT              0xFE

#define ZCL_CMD_ONOFF_OFF                                 	0x00
#define ZCL_CMD_ONOFF_ON                                  	0x01
#define ZCL_CMD_ONOFF_TOGGLE                              	0x02

#define ZCL_ONOFF_STATUS_OFF                              	0x00
#define ZCL_ONOFF_STATUS_ON                               	0x01

typedef struct tag_zcl_report_table{
	uint8_t endpoint;
	uint16_t cluster;
	bool reportEnable;
	bool sceneRecallFlg;
	bool reportGatewayEnable;
	bool reportChildDeviceEnable;
	addrExt_t maskEui64Addr;
	uint8_t dest_endpoint;
}ZclReportTableSt;

#define MAX_ATTR_CHANGE_SUPPORT_NUMS					  8
typedef void (*pClusterAttributeChangeCallback)(uint8_t endpoint,uint16_t cluster,uint16_t attribute,uint8_t *data,uint8_t data_type);

typedef struct {
	uint16_t cluster;
	pClusterAttributeChangeCallback change_callback;
}AttributeChangeConfSt;


typedef void (*pOnOffClusterOnOffStatusCallback)(uint8_t endpoint, OnOffStatusEnum estatus );

void kZclOnOffClusterServerOnOffSet(uint8_t endpoint,bool onoff);
extern status_t zcl_attrWrite(u8 endpoint, u16 clusterId, zclWriteRec_t *pWriteRec, bool enable);
extern zclAttrInfo_t *zcl_attrRead(u8 endpoint, u16 clusterId, u16 attrId, status_t *status);

#define  ReadServerAttribute(endpoint,clusterId,attributeID,status)  (zcl_attrRead(endpoint,clusterId,attributeID,status))

#define  kGetLastRssi()    				(g_sysDiags.lastMessageRSSI)
#define  kGetLastLQI()    				(g_sysDiags.lastMessageLQI)

void Update_Local_Attribute_Info(void);
bool kIsKonkeRemoteGateway(void);

kk_err_t kZclOnOffClusterServerInit(pOnOffClusterOnOffStatusCallback pOnOffStatusCallback );
void ikkAttributeChangeCallbackRegister(AttributeChangeConfSt *ConfSt,uint8_t num);
void ON_OFF_Cmd_Handler(uint8_t endpoint,uint8_t cmd);

bool kZclOnOffClusterServerOnOffGet(uint8_t endpoint);

kk_err_t kZclOnOffClusterServerOnOffControl(uint8_t endpoint, OnOffCtrlEnum ctrlopt );

bool  Get_Model_ID(uint8_t *ModeID);
bool kkClusterGetReportingPeriod(uint8_t endpoint, uint16_t cluster_id, uint16_t attribute_id,uint16_t *min_interval, uint16_t *max_interval );
void kOptTunnelReportingPlagiarizeOriginal(uint8_t endpoint, uint16_t clusterId, uint16_t attributeId );
void kOptTunnelReportingStatus(uint8_t endpoint, uint16_t clusterId, uint16_t attributeId );
void kZclClusterPermitReportTableInit(BindObjSt clusterBindList[], uint8_t size);
bool kZclClusterGetPermitReportInfo(uint8_t endpoint, uint16_t cluster, ZclReportTableSt *zclReportPermit);
bool kZclClusterSetPermitReportInfo(uint8_t endpoint, uint16_t cluster, bool reportEnable, bool sceneRecallFlg
					, bool reportGatewayEnable, bool reportChildDeviceEnable, uint8_t *maskEui64Addr, uint8_t dest_endpoint);
#endif /* _SAMPLE_LIGHT_H_ */
