#pragma once
#include "app_config.h"
#include "ui/ui_api.h"
#include "ui/ui.h"
#include "ui/ui_style.h"
#include "app_task.h"
#include "app_main.h"
#include "ui/ui_number.h"
#include "ui/ui_text.h"
#include "asm/includes.h"
#include "system/includes.h"
#include "os/os_api.h"
#include "circular_buf.h"
#include "ui/qr_code.h"
#include "audio_config.h"


#define USR_NAME	512
#define QRCODE_SIZE  256
#define QRCODE_NAME  512

#define MAX_STR_LEN_16       (16)
#define MAX_ID_LEN           (16)
#define MAX_HOMEPAGE_NUM   (20)//首页听单最大个数
#define MAX_ALBUM_PER_PAGE   (20) //请求专辑列表时每页获取的专辑个数，最大设置为20
#define MAX_NAME_LEN      (128)

//听单列表信息
typedef struct{
    uint8_t pay_type;                       //支付类型(专辑：0=免费,1=vip,2=精品单购,3=限免；音频：0=免费,1=付费,2=试听,3=限免)
    uint8_t index;                      //index索引
	char listen_name[MAX_STR_LEN_16];       //听单名称
	char listen_id[MAX_ID_LEN];          //听单id
}listen_list_info;


//返回的首页结构体
typedef struct { 
    uint8_t listen_total;   //听单总数
	u8 sel_item;
    listen_list_info listen_array[MAX_HOMEPAGE_NUM];  //音频列表信息
} homepage_info;


//声音列表信息
typedef struct{
	uint8_t pay_type;                   //支付类型 (专辑：0=免费,1=vip,2=精品单购,3=限免；音频：0=免费,1=付费,2=试听,3=限免)
	uint16_t index;                     //列表索引index
	uint16_t play_duration;                  //音频时长
	uint16_t break_point;               //收听历史列表中记录的音频断点
	char title[MAX_NAME_LEN];         //音频名称
	char album_id[MAX_ID_LEN];       //专辑id
	char track_id[MAX_ID_LEN];       //音频id
	char history_track_id[MAX_ID_LEN];   //收听历史列表中记录的音频id
	char timeline[MAX_STR_LEN_16];       //收藏列表中分割时间点
}source_list_info_t;

//返回的声音列表结构体
typedef struct { 
	u8 sel_item;
    uint16_t source_total;  //资源总数
    uint16_t source_num;     //当前页资源数量
    uint16_t cur_page;       //当前页码
    uint8_t data_type;      // 0:专辑列表， 1：音频列表
    source_list_info_t source_array[MAX_ALBUM_PER_PAGE];  //音频列表信息
} source_list_info;


typedef struct
{
	u8 * name;
	bool vip;// 0--isn't vip 1--is vip
}himalaya_usr;

typedef struct{
	himalaya_usr usr;
	OS_MUTEX mutex;
	u8 core;	
	u8 track_grid_row;
	u8 track_page_mode;
	u8 track_page_level;//一级页面 二级页面
	char player_title[128];
	char url[128];
	u8 play_status;
	u8 *usr_name;
	u8 usr_vip;
}ui_manage_info;

typedef struct
{
	ui_manage_info ui;
	homepage_info homepage;
	source_list_info source_list;//homepage->track
	source_list_info track_list;
	source_list_info favorite_list;
	source_list_info history_list;
}himalaya_info;
#define INFO_SIZE	sizeof(himalaya_info)

extern himalaya_info * ui_info;
#define __this ui_info
#define __usr_name __this->ui.usr_name



struct _H_QRCODE {
    int code128_mode;
    u8 qr_version;
    u8 qr_max_version;
    u8 qr_ecc_level;
    int qr_code_max_input_len;
    int qr_buf_size;
    int img_w;
    int out_size;
    int line_size;
};

typedef struct
{
	u8 *title;
	u8 *mess;
	u8 *row_img;
	u8 *copy_row_img;
	jl_code_param_t param;
	struct _H_QRCODE data;
}himalaya_qr;
extern himalaya_qr * qr;
#define __qr qr

enum
{
	CMD_INIT,	
	CMD_RELEASE,	
	CMD_NET_CHECK,	
	CMD_GET_HOMEPAGE,	
	CMD_GET_PRIVACY,	
	CMD_CLEAR,	
	CMD_HOMEPAGE_ALBUM_BY_LISTENID,
	CMD_USR_ACCOUNT,
	CMD_USR_HISTORY,
	CMD_USR_SUBSCRIBE,
	CMD_HISTORY_TRACK_BY_LISTENID,
};

enum UI_CORE
{
	INIT_H,
	LINK_H,
	PRIVARY_H,
	PERSONAL_H,
	QRCODE_H,
	ACCOUNT_INFO_H,
	HISTORY_H,
	ALBUM_H,
	TRACK_LIST_H,
	ACCOUNT_QUIT_H,
	LAYOUT_QUIT_H,
	PLAYER_H,
	VOLUME_H,
};

enum H_MSG
{
	MSG_HOMEPAGE_LIST,			//0-首页播单
	MSG_TRACK_LIST,				//1-音频列表
	MSG_TURN_PLAYER,			//2-播放器
	MSG_USR_LOGIN,				//3-已登录
	MSG_USR_UNLOGIN,			//4-未登录
	MSG_USR_PERSONAL_CENTER,	//5-个人中心
	MSG_USR_HISTORY_LIST,		//6-历史记录
	MSG_USR_ALBUM_LIST,			//7-专辑列表
	MSG_REFRESH_TRACK,
	MSG_MUSIC_PAUSE,
};

enum
{
	TRACK_RESET,
	TRACK_TRACK,
	TRACK_HOMEPAGE,
	TRACK_PERSONAL,
	TRACK_HISTORY,
	TRACK_PLAYER,
	TRACK_LEVEL,
	TRACK_LEVEL_I,
	TRACK_LEVEL_II,
};


enum
{
	HIMALAYA_URL			=0,
	HIMALAYA_PAUSE			=1,		//暂停播放
	HIMALAYA_RESTART		=2,		//开始播放
	HIMALAY_KILL_TMP		=3,		//预留自杀位
	HIMALAYA_PREV			=4,		//前进播放
	HIMALAYA_BACK			=5,		//后退播放
	HIMALAYA_REPEAT			=6,		//顺序播放
	HIMALAYA_LOOP			=7,		//单曲循环
	HIMALAYA_RAND			=8,		//随机播放
};

enum
{
	MUSIC_PAUSE,	
	MUSIC_PLAY,	
};

