#ifndef _REPORT_H
#define _REPORT_H

#include "ramdata.h"

#define MAX_RECORDS_SAVED		7
#define MAX_CALL_TYPE			16

typedef struct account_report
{
   u_long    user_num[MAX_USER_TYPE];
   u_long    total_num;
   double   total_balance;
}_account_report;


typedef struct prepaid_card_report
{
   float      face_value[MAX_VALUE_TYPE];
   u_long     used_today[MAX_VALUE_TYPE];
   u_long     total_used[MAX_VALUE_TYPE];
   u_long     unused[MAX_VALUE_TYPE];  
}_prepaid_card_report;


 
typedef enum call_type
{
   	INCOMING_CALL = 0,
   	LOCAL_CALL_OUT,  
   	IDD_CALL,
   	NDD_CALL,
   	RENT_CHARGE,
   	AST_RECHARGE,
   	AST_CHARGE,
   	RECHARGE_SUC,
   	RECHARGE_FAIL,
   	SHORT_MESSAGE,
   	CONFERENCE_CALL,
	SERVICE_CHARGE,
	SERVICE_GPRS = 16,
	SERVICE_CCC,
	MAX_SERVICE_TYPE,
}_call_type;

typedef struct call_record
{
   int      call_type;
   u_long   call_times;
   u_long   call_duration;
   double   call_charge;
}_call_record;

typedef struct gprsRecord
{	
   	long long gprsVolume;
	long long gprsDuration;
	double	  gprsCharge;
}_gprs_record;

typedef struct _pps_vas_record
{
    u_long	smsNumber;
	double	smsCharge;
	u_long	mmsSendNumber;
	double	mmsSendCharge;
	u_long	mmsRetrieveNumber;
	double	mmsRetrieveCharge;
	u_long	mmsEmailNumber;
	double	mmsEmailCharge;
}_pps_vas_record;

typedef struct call_report
{
   u_long			total_call_num;
   u_long			total_call_duration;
   double			total_call_charge;
   _call_record  	call_record[MAX_CALL_TYPE];
   _gprs_record		gprs_record;
   _pps_vas_record	vas_record;
}_call_report;

typedef struct balance_summary
{
   double   yesterday_balance;
   double   today_recharge;
   double   today_charge;
   double   today_balance;
}_balance_summary;

#ifdef _ZED_NO_CALLER_NUM_AND_EXPIRY_DATE_ // ussd_code daily report
#define USSDCODE_QUERY_CODE_STR "114"
#define USSDCODE_TOPUP_CODE_STR "113"
#define USSDCODE_HOTLINE_CODE_STR "117"

#define USSDCODE_TYPE_QUERY 0
#define USSDCODE_TYPE_TOPUP 1
#define USSDCODE_TYPE_HOTLINE 2
#define USSDCODE_TYPE_CHANNEL 3
#define USSDCODE_MAX_CODE_NUM 8

#define USSDCODE_STAT_REQ 0
#define USSDCODE_STAT_DUR 1
#define USSDCODE_STAT_ERR_TIMEOUT 2
#define USSDCODE_STAT_ERR_SYSTEM 3
#define USSDCODE_STAT_ERR_MSG 4

typedef struct ussdcode_report
{
   char   code[8];// 114,113,117,101/707
   //char   type[12];// query,topup,hotline,channel
   unsigned int req_count;
   unsigned int req_duration;// Sec

   unsigned int err_timeout_count;
   //unsigned int err_network_count;
   unsigned int err_system_count;
   unsigned int err_msg_count;
}_ussdcode_report;

int	pps_update_ussd_code_state(char *code, int type, int result, int dur);
#endif

typedef struct daily_report
{
   int					  year_month_day[3];
   _account_report        account_report;
   _prepaid_card_report   prepaid_card_report;
   _call_report			  call_report;
   _balance_summary		  balance_summary;
#ifdef _ZED_NO_CALLER_NUM_AND_EXPIRY_DATE_ // ussd_code daily report
	_ussdcode_report ussdcode_report[USSDCODE_MAX_CODE_NUM];
#endif
}_daily_report;

typedef struct _pps_report
{
   int   ptrTail;
   int   saveHead;
   int   saveTail;
   _daily_report  daily_report[MAX_RECORDS_SAVED];
   _daily_report  peer_daily_report[MAX_RECORDS_SAVED];
}_pps_report;


void reportInit();
int  reportCreatedDaily();
int  reportCDRIncrement(int calltype, int duration, float charge,ulong gprsVolume);
int  reportAccount(int segmentno);
int  reportPrepaidCard(int segmentno);
int  GetDailyReport(u_char oidLen, DWORD *oid, u_char *pdata, BYTE *vartype);

#endif
