#ifndef _RESTAPI_H
#define _RESTAPI_H

#include "../../../../plat/public/src/include/public.h"

#define	MAX_BODY_LEN	128

#define REST_PROXY_PORT	4951

enum RESULT_TYPE 
{
	RES_SUCCEED = 0,
	RES_FAILED = 1,
};

enum ERROR_CODE 
{
	ERR_REST_SUCCESS = 2001,
	ERR_REST_COMMAND_UNSUPPORTED=3001,
	ERR_REST_UNKNOWN_PEER = 3010,
	ERR_REST_INVALID_USER_STATUS = 4001,
	ERR_REST_DEST_USER_NOT_ALLOWED = 4008,
	ERR_REST_CREDIT_LIMIT = 4012,
	ERR_REST_INVALID_PARAMETER_VALUE=5004,
	ERR_REST_MISSING_PARAMETER = 5005,
	ERR_REST_INVALID_RECHARGE_PWD = 5006,
	ERR_REST_UNABLE_TO_COMPLY=5012,
	ERR_REST_USER_UNKNOWN = 5030,
};

enum REST_PROXY_MSG_TYPE 
{
	REST_QUERY=1,
	REST_TOPUP=2,
	REST_TRANSFER=3,

	// for selfcare
	REST_SEND_AUTHCODE_REQ=5,
	REST_SEND_AUTHCODE_RSP=6,
	REST_QUERY_USERDATA_REQ=7,
	REST_QUERY_USERDATA_RSP=8,
	REST_BUNDLE_SUBS_REQ=9,
	REST_BUNDLE_SUBS_RSP=10,
	REST_BUNDLE_USAGE_REQ=11,
	REST_BUNDLE_USAGE_RSP=12,
	REST_RECHARGE_REQ=13,
	REST_RECHARGE_RSP=14,
	REST_TRANSFER_REQ=15,
	REST_TRANSFER_RSP=16,
	REST_RECHARGE_CARD_REQ=17,
	REST_RECHARGE_CARD_RSP=18,
	REST_CHECK_BALANCE_REQ=19,
	REST_CHECK_BALANCE_RSP=20,
	REST_QUERY_BALANCE_REQ=21,
	REST_QUERY_BALANCE_RSP=22,
	//
};

#if 0
enum PAY_TYPE
{
	PAY_TYPE_BALANCE = 1,
	PAY_TYPE_PAYPAL = 2,
	PAY_TYPE_VISA = 3,
	PAY_TYPE_MASTER = 4,
};

enum ACCT_STATUS
{
    AS_FRESH,           /* fresh account, can't dial in or out, 
                              but can recharge. */
    AS_NORMAL,      /* normal account */
    AS_SUSPEND,
    AS_BLACKLIST,
    AS_RELEASED,
    AS_OPRTRIAL,
    //AS_MAX_USER_TYPE,

    AS_EXTERNAL=10,
};
#endif

enum REST_IE_TAG
{
	IE_SRC_REF=1,
	IE_DST_REF,
	IE_MSISDN,
	IE_RESULT,
	IE_ERROR_CODE,
	IE_BALANCE,
	IE_MO_EXPIRY,
	IE_MT_EXPIRY,
	IE_USERNAME,
	IE_PASSWORD,
	IE_MSG_CONTENT,
	IE_STATUS,
	IE_REMARK,
	IE_GROUP_NAME,
	IE_MO_VOICE_MIN,// in minute
	IE_REMAIN_MO_VOICE_SEC,// in second
	IE_REMAIN_MO_VOICE_MIN,// in minute
	IE_MT_VOICE_MIN,// in minute
	IE_REMAIN_MT_VOICE_SEC,// in second
	IE_REMAIN_MT_VOICE_MIN,// in minute
	IE_SMS_NUM,
	IE_REMAIN_SMS_NUM,
	IE_DATA_VOL_MB,// in MB
	IE_REMAIN_DATA_VOL_KB,// in KB
	IE_REMAIN_DATA_VOL_MB,// in MB
	IE_PAY_TYPE,
	IE_AMOUNT,
	IE_VALID_DAYS,
	IE_EXPIRY_TIME,
	IE_MSISDN_TRANS_OUT,
	IE_MSISDN_TRANS_IN,
	IE_BALANCE_AVAILABLE,
	IE_RECHARGE_AMOUNT,
};

typedef struct rest_header
{
	u16	src_ref;
	u16	dst_ref;
}_rest_header;

typedef struct rest_query
{
	char	msisdn[24];
}_rest_query;

typedef struct rest_query_res
{
	u8	optional_flag;
	u8	result;
	u8	error_code;
	u32	balance;
	u32	mo_expiry;
	u32	mt_expiry;
}_rest_query_res;

typedef struct rest_topup
{
	char	msisdn[24];

	char	username[24];
	char	password[24];
}_rest_topup;


typedef struct rest_topup_res
{
	u8	optional_flag;
	u8	result;
	u8	error_code;
	u32	balance;
	u32	mo_expiry;
	u32	mt_expiry;
}_rest_topup_res;

// for selfcare =============================
typedef struct rest_send_authcode_req
{
	char	msisdn[24];
	char	sms_content[128];
}_rest_send_authcode_req;

typedef struct rest_send_authcode_rsp
{
	u8	optional_flag;
	u8	result;
	u32	error_code;
}_rest_send_authcode_rsp;

typedef struct rest_query_user_data_req
{
	char	msisdn[24];
}_rest_query_user_data_req;

typedef struct rest_query_user_data_rsp
{
	u8	optional_flag;
	u8	result;
	u32	error_code;

	char	msisdn[24];
	u8    status;// use ACCT_STATUS
	char remark[64];
	char usrGrpName[64];// usr data==>cos id==>cos title
	u32	balance;
	u64	mo_expiry;
	u32	mo_voc_min;// in Min
	u32	remain_mo_voc_min;
	u32	mt_voc_min;// in Min
	u32	remain_mt_voc_min;
	u32	total_sms_num;// reserved, set to 0 or do not send
	u32	remain_sms_num;
	u32	total_data_vol;// reserved, set to 0 or do not send
	u32	remain_data_vol;// MB
}_rest_query_user_data_rsp;

typedef struct rest_bundle_subs_req
{
	char	msisdn[24];
	u8 payType;// 1: balance; 2: paypal; 3: visa; 4: master, use PAY_TYPE
	u32 charge;// Conditional, mandatory if balance
	u32 moVoiceMinute;
	u32 mtVoiceMinute;
	u32 dataVolume;// MB
	u32 smsNum;
	u32 validDays;
}_rest_bundle_subs_req;


typedef struct rest_bundle_subs_rsp
{
	u8	optional_flag;
	u8	result;
	u32	error_code;
}_rest_bundle_subs_rsp;


typedef struct rest_bundle_usage_req
{
	char	msisdn[24];
}_rest_bundle_usage_req;


typedef struct rest_bundle_usage_rsp
{
	u8	optional_flag;
	u8	result;
	u32	error_code;
	u32	moVoiceInSec;// remained mo voice in second
	u32	mtVoiceInSec;// remained mt voice in second
	u32  dataVolInKB;// remained data volume in KB
	u32  smsNum;// remained sms
	u64  expiredTime;// expired time
}_rest_bundle_usage_rsp;


typedef struct rest_recharge_req
{
	char	msisdn[24];

	u32	amount;// mandatory, add to balance
}_rest_recharge_req;


typedef struct rest_recharge_rsp
{
	u8	optional_flag;
	u8	result;
	u32	error_code;
	u32	balance;// current balance
	u64	expiredTime;// expired time
}_rest_recharge_rsp;


typedef struct rest_transfer_req
{
	char	transferOutMsisdn[24];
	char	transferInMsisdn[24];

	u32	amount;// mandatory
}_rest_transfer_req;


typedef struct rest_transfer_rsp
{
	u8	optional_flag;
	u8	result;
	u32	error_code;
	u32	balance;
}_rest_transfer_rsp;


typedef struct rest_recharge_card_req
{
	char	msisdn[24];

	char	cardPwd[32];// rechare card password
	//u32	amount;// mandatory, add to balance
}_rest_recharge_card_req;


typedef struct rest_recharge_card_rsp
{
	u8	optional_flag;
	u8	result;
	u32	error_code;
	u32	rechargeAmount;// mandatory, add to balance
	u32	balance;// current balance
	u64	expiredTime;// expired time
}_rest_recharge_card_rsp;


typedef struct rest_check_balance_req
{
	char	msisdn[24];

	u32	amount;// mandatory
}_rest_check_balance_req;


typedef struct rest_check_balance_rsp
{
	u8	optional_flag;
	u8	result;
	u32	error_code;
	u8	available;// 0: enough balance; 1: else
}_rest_check_balance_rsp;


typedef struct rest_query_balance_req
{
	char	msisdn[24];
}_rest_query_balance_req;


typedef struct rest_query_balance_rsp
{
	u8	optional_flag;
	u8	result;
	u32	error_code;
	u32	balance;// current balance
}_rest_query_balance_rsp;
//======================================

typedef struct rest_msg_s
{
	u8	msg_type;
	_rest_header header;	
	union	
	{
		_rest_query	query;
		_rest_query_res	query_res;
		_rest_topup	topup;
		_rest_topup_res	topup_res;

        // for selfcare
		_rest_send_authcode_req send_authcode_req;
		_rest_send_authcode_rsp send_authcode_rsp;
		_rest_query_user_data_req query_user_data_req;
		_rest_query_user_data_rsp query_user_data_rsp;
		_rest_bundle_subs_req bundle_subs_req;
		_rest_bundle_subs_rsp bundle_subs_rsp;
		_rest_bundle_usage_req bundle_usage_req;
		_rest_bundle_usage_rsp bundle_usage_rsp;
		_rest_recharge_req recharge_req;
		_rest_recharge_rsp recharge_rsp;
		_rest_transfer_req transfer_req;
		_rest_transfer_rsp transfer_rsp;
		_rest_recharge_card_req recharge_card_req;
		_rest_recharge_card_rsp recharge_card_rsp;
		_rest_check_balance_req check_balance_req;
		_rest_check_balance_rsp check_balance_rsp;
		_rest_query_balance_req query_balance_req;
		_rest_query_balance_rsp query_balance_rsp;
		//
	}msg;
}_rest_msg_s;

int encode_rest_query(_rest_msg_s *ptr, u8 *buf);

int encode_rest_query_res(_rest_msg_s *ptr, u8 *buf);

int encode_rest_topup(_rest_msg_s *ptr, u8 *buf);

int encode_rest_topup_res(_rest_msg_s *ptr, u8 *buf);

int decode_rest_api_msg(u8 *buf, int len, _rest_msg_s *ptr);

// for selfcare======================================
int encode_rest_send_authcode_req(_rest_msg_s *ptr, u8 *buf);
int encode_rest_send_authcode_rsp(_rest_msg_s *ptr, u8 *buf);
int encode_rest_query_user_data_req(_rest_msg_s *ptr, u8 *buf);
int encode_rest_query_user_data_rsp(_rest_msg_s *ptr, u8 *buf);
int encode_rest_bundle_subs_req(_rest_msg_s *ptr, u8 *buf);
int encode_rest_bundle_subs_rsp(_rest_msg_s *ptr, u8 *buf);
int encode_rest_bundle_usage_req(_rest_msg_s *ptr, u8 *buf);
int encode_rest_bundle_usage_rsp(_rest_msg_s *ptr, u8 *buf);
int encode_rest_recharge_req(_rest_msg_s *ptr, u8 *buf);
int encode_rest_recharge_rsp(_rest_msg_s *ptr, u8 *buf);
int encode_rest_transfer_req(_rest_msg_s *ptr, u8 *buf);
int encode_rest_transfer_rsp(_rest_msg_s *ptr, u8 *buf);
int encode_rest_recharge_card_req(_rest_msg_s *ptr, u8 *buf);
int encode_rest_recharge_card_rsp(_rest_msg_s *ptr, u8 *buf);
int encode_rest_check_balance_req(_rest_msg_s *ptr, u8 *buf);
int encode_rest_check_balance_rsp(_rest_msg_s *ptr, u8 *buf);
int encode_rest_query_balance_req(_rest_msg_s *ptr, u8 *buf);
int encode_rest_query_balance_rsp(_rest_msg_s *ptr, u8 *buf);
//

#endif
