#ifndef ASSISTANT_H
#define ASSISTANT_H
#ifdef __cplusplus
extern "C" {
#endif

#define MAX_TIP_LEN         (60 * 4 + 1)
#define MAX_ALARM_ITEMS     (1024)

typedef enum
{
    ASSISTANT_TYPE_CLOCK        = 0,
    ASSISTANT_TYPE_REMAIND,
    ASSISTANT_TYPE_SESSION,
} ASSISTANT_TYPE;

typedef enum
{
    STATUS_IDLE             = 0,
    STATUS_PREPARE_STANDBY,
    STATUS_RUNNING,
    STATUS_NOT_IN_USE,
    STATUS_REMOVE_ITEM,
    STATUS_ADD_ITEM,
} ASSISTANT_STATUS;

typedef struct
{
    unsigned long long      itemId;					///< 提醒、闹钟ID
    ASSISTANT_TYPE          itemType;				///< 类型: 0 闹钟, 1 提醒
    int                     priority;				///< 优先级: 暂未使用
    REPEAT_MODE             repeatMode;				///< 重复模式

    int          			year;					///< 年
    int         			month;  				///< 月
    int         			day;					///< 日
    int         			hour;   				///< 小时
    int         			minute; 				///< 分钟
    int         			second; 				///< 秒钟
    int         			weekDay;				///< 星期
                                                    
    unsigned int            timerId;		    	///< 关联的定时器ID
    unsigned long long      voiceId;		    	///< 闹钟资源ID
    char                    strTips[MAX_TIP_LEN];   ///< 提醒 TTS 文本
    char                    resUrl[2048];           ///< 资源URL
    char                    voiceRes[32];           ///< 资源声音文件ID
    char                    voiceResType[64];       ///< 资源类型
} ASSISTANT_ITEM_INFO, *PASSISTANT_ITEM_INFO;

typedef struct
{
    int                     nItems;					///< 协议包含的数据个数
    PASSISTANT_ITEM_INFO    pAlarmInfo;				///< 提醒、闹钟数据详细信息
} ASSISTANT_SYNC_INFO, *PASSISTANT_SYNC_INFO;

typedef struct ASSISTANT_ARRAY_INFO
{
    ASSISTANT_ITEM_INFO             alarmItem;
    struct ASSISTANT_ARRAY_INFO     *next, *prev;
} *PASSISTANT_ARRAY_INFO;

typedef struct
{
    int						cmd;
    int                     nItems;
    ASSISTANT_TYPE          type;
    unsigned long long      ids[MAX_ALARM_ITEMS];
} ASSISTANT_NOTIFY_INFO, *PASSISTANT_NOTIFY_INFO;

typedef struct
{
    int                 cmd;
    int                 val;
} ASSISTANT_RSP_STATUS, *PASSISTANT_RSP_STATUS;

typedef struct
{
    int                 cmd;
    int                 val;
    int                 errCode;
} ASSISTANT_NOFIFY_EVENT, *PASSISTANT_NOFIFY_EVENT;

static void __printAssistantNofifyInfo(const char *pTags, PASSISTANT_NOTIFY_INFO pInfo)
{
    int i;
    if(pTags && strlen(pTags) > 0)
    {
        LOG_EX2(LOG_Debug, "%s:\n", pTags);
        LOG_EX2(LOG_Debug, "**************************************************************\n");
    }

    LOG_EX2(LOG_Debug, "Sync Items     :       %d\n", pInfo->nItems);
    LOG_EX2(LOG_Debug, "-------------------------\n");
    LOG_EX2(LOG_Debug, "| Alarm Id |    Type     |\n");
    LOG_EX2(LOG_Debug, "-------------------------\n");

    for(i = 0; i < pInfo->nItems; i++)
    {
        LOG_EX2(LOG_Debug, "| %8llu | %11s |\n", 
                pInfo->ids[i], 
                (pInfo->type == ASSISTANT_TYPE_REMAIND) ? "Remaind" : "Alarm Clock");
    }
  
    LOG_EX2(LOG_Debug, "-------------------------\n");
}

static void __printAssistantSyncInfo(const char* pTags, PASSISTANT_SYNC_INFO pInfo)
{
    int i;
    char buf[MAX_PATH];
    struct  tm  localTime;
    time_t  tmStamp;

    if(pTags && strlen(pTags) > 0)
    {
        LOG_EX2(LOG_Debug, "%s:\n", pTags);
        LOG_EX2(LOG_Debug, "**************************************************************\n");
    }

    //fprintf(stdout, "Command        :       %d(%08X)\n", pInfo->cmd, pInfo->cmd);
    LOG_EX2(LOG_Debug, "Sync Items     :       %d\n", pInfo->nItems);

    LOG_EX2(LOG_Debug, "---------------------------------------------------------------------"
            "-----------------------------------------------------------\n");

    LOG_EX2(LOG_Debug, "| Alarm Id |    Type     | Priority |  Repeat Mode    |   Week Day    |"
                       "       DateTime       |         Tips         | Resource |\n");
    
    LOG_EX2(LOG_Debug, "---------------------------------------------------------------------"
            "-----------------------------------------------------------\n");

    for(i = 0; i < pInfo->nItems; i++)
    {
        memset(buf, 0, MAX_PATH);
        
        sprintf(buf, "%04u-%02u-%02u %02u:%02u:%02u",
                (pInfo->pAlarmInfo[i].year == -1)   ? 1900 : pInfo->pAlarmInfo[i].year + 1900, 
                (pInfo->pAlarmInfo[i].month == -1)  ? 0    : pInfo->pAlarmInfo[i].month + 1, 
                (pInfo->pAlarmInfo[i].day == -1)    ? 0    : pInfo->pAlarmInfo[i].day,
                (pInfo->pAlarmInfo[i].hour == -1)   ? 0    : pInfo->pAlarmInfo[i].hour, 
                (pInfo->pAlarmInfo[i].minute == -1) ? 0    : pInfo->pAlarmInfo[i].minute, 
                (pInfo->pAlarmInfo[i].second == -1) ? 0    : pInfo->pAlarmInfo[i].second);

        LOG_EX2(LOG_Debug, "| %8llu | %11s | %8d | %15s |   %d%d%d%d %d%d%d%d   | %20s | %20s | %8llu |\n", 
                pInfo->pAlarmInfo[i].itemId,
                (pInfo->pAlarmInfo[i].itemType == ASSISTANT_TYPE_REMAIND) ? "Remaind" : "Alarm Clock",
                pInfo->pAlarmInfo[i].priority,
                DumpTimerRepeatModeString(pInfo->pAlarmInfo[i].repeatMode),
                (pInfo->pAlarmInfo[i].weekDay & (1 << 7))? 1 : 0, 
                (pInfo->pAlarmInfo[i].weekDay & (1 << 6))? 1 : 0, 
                (pInfo->pAlarmInfo[i].weekDay & (1 << 5))? 1 : 0, 
                (pInfo->pAlarmInfo[i].weekDay & (1 << 4))? 1 : 0, 
                (pInfo->pAlarmInfo[i].weekDay & (1 << 3))? 1 : 0, 
                (pInfo->pAlarmInfo[i].weekDay & (1 << 2))? 1 : 0, 
                (pInfo->pAlarmInfo[i].weekDay & (1 << 1))? 1 : 0, 
                (pInfo->pAlarmInfo[i].weekDay & (1 << 0))? 1 : 0, 
                buf,
                pInfo->pAlarmInfo[i].strTips,
                pInfo->pAlarmInfo[i].voiceId);
    }
    
    LOG_EX2(LOG_Debug, "---------------------------------------------------------------------"
            "-----------------------------------------------------------\n");
}
#ifdef __cplusplus
}
#endif                    
#endif