/* 
** The module Copyright (C) 2000-2008 interWAVE Inc.
** Written completely by Liang Hongbin 
*/

#ifndef RAMDATA__H
#define RAMDATA__H
#include    <sys/types.h>

#define RAMDATA_PACK_SIZE     1024
#define RAMDATA_PACK_NUM      (60*1024)
#define RAMDATA_BLOCK_SIZE    (RAMDATA_PACK_SIZE*RAMDATA_PACK_NUM)    /* Ram block size is 24MB */

#define	T_LOW_BALANCE		1
#define	T_EXPIRED		1

#define	 POOL_MAX_CHILD				5

#define	OCS_WITH_CRM 1

typedef enum account_status {
    T_FRESH,           /* fresh account, can't dial in or out, 
                              but can recharge. */
    T_NORMAL,          /* normal account */
    T_SUSPEND,
    T_BLACKLIST,
    T_RELEASED,
    T_OPRTRIAL,
    T_DISABLE,
    MAX_USER_TYPE,

    T_EXTERNAL=10,
} _account_status;

typedef struct data_info
{
	u_char  version[3];
	u_long  dataSize;
}_data_info;

typedef enum favorite_number{
	NOT_FAVORITE_NUMBER,
	FAVORITE_NUMBER,
}_favorite_number;

typedef enum last_call{
	LST_MO_CALL,
	LST_MT_CALL,
	LST_MF_CALL,
	LST_MO_SMS,
}_last_call;

#define	MAX_FAVORITE_NUMBERS		5
#define MAX_MSISDN_BLEN			10
#define	MIN_MSISDN_ALEN		6
#define MAX_MSISDN_ALEN		16
#define	MAX_PIN_LEN		6
#define	MAX_HOME_LOCATION	4
#define   MAX_PPS_USER_FIELD_NUMS   68

typedef struct prepaid_info_old {
	u_char		msisdn[MAX_MSISDN_BLEN];
	char			pin[MAX_PIN_LEN]; 
	u_char		status;
	double		balance;
	double		promo_balance;
	long			overdraft;
	u_long		first_used_date;
	u_long		mo_expiration_date;   /* outgoing  */
	u_long		mt_expiration_date; /* incoming */
	u_long		promo_date;
	u_char		cos_id;
	u_char		rent_type;
	u_char		home_location[MAX_HOME_LOCATION];
	u_short		cug_id;
	u_char		language_type; 
	u_char		recharge_fail;
	u_char		free_sm_counter;
	u_char		latch_flag;
	u_char		favorite_numbers;  
		/* favorite number set flag
			0=no favorite number set,
			otherwise = favorite number sets */
	u_char		fav_change_counter;  /* favorite number edit counter */
	u_char		favorite_number[MAX_FAVORITE_NUMBERS][MAX_MSISDN_BLEN];	
	u_char		last_call_type;
	u_long		last_call_date;
	u_char		last_call_number[MAX_MSISDN_BLEN];
	double		in_net_cap_sms_balance;
	u_short		in_net_cap_sms_counter;
	double		out_net_cap_sms_balance;
	u_short		out_net_cap_sms_counter;	
	double		in_net_cap_balance;
	double		out_net_cap_balance;
	double		in_net_cap_call_balance;
    u_long		in_net_cap_call_duration;
    double		out_net_cap_call_balance;
    u_long		out_net_cap_call_duration;
	
} _prepaid_info_old;

typedef struct last_call_info
{
	u_char				 last_call_type;
	u_long				 last_call_date;
	u_char				 last_call_number[MAX_MSISDN_BLEN];
}_last_call_info;

typedef struct{
	u_char	childNumber;
	u_char	changeTimes;
	u_char	childMsisdn[POOL_MAX_CHILD][MAX_MSISDN_BLEN];
}PoolParent;

typedef struct{
	u_char		parentMsisdn[MAX_MSISDN_BLEN];
	u_short		callsToday;
	u_short		smsToday;
	double		chargedToday;
}PoolChild;

typedef struct{
	u_char 	role;
	struct{
		PoolParent 	parent;
		PoolChild 	child;
	}roleParty;
}UserData_Pool_Account;

typedef struct bundle_info
{
	long long		data;	/*left in, in B */
	int			mo_voice;	/* in seconds */
	int			mt_voice;
	u_short		sms;
	u_long		validity_date;
	int			warning_sms_flag;// If has already sent sms notification for bundle insufficent, will not send notification again
	char			cRes[4];
	int			iRes[2];
}_bundle_info;

typedef struct crm_info
{
	int			customer_id;
	int			account_id;
	int			product_id;
	u_long		birthday;
	int			base_plan_id;
	int			rent_charge;
	int			new_plan_id;
	int			new_rent_charge;
	u_char		vas_cug_state;		/*0=not used, 1=normal, 2=suspended */
	u_long		ulRes[4];
	int			iRes[4];
	u_char		user_class;
	u_char		ucRes[3];
}_crm_info;


typedef struct prepaid_info {
	u_char		msisdn[MAX_MSISDN_BLEN];
	char			pin[MAX_PIN_LEN]; 
	u_char		status;
	double		balance;
	double		promo_balance;
	long			overdraft;// amount that can overdraft
	u_long		first_used_date;
	u_long		mo_expiration_date;   /* outgoing  */
	u_long		mt_expiration_date; /* incoming */
	u_long		promo_date;
	u_char		cos_id;
	u_char		rent_type;
	u_char		home_location[MAX_HOME_LOCATION];
	u_short		cug_id;
	u_char		language_type; 
	u_char		recharge_fail;
	u_char		free_sm_counter;
	u_char		latch_flag;
	u_char		favorite_numbers;  
		/* favorite number set flag
			0=no favorite number set,
			otherwise = favorite number sets */
	u_char		fav_change_counter;  /* favorite number edit counter */
	u_char		favorite_number[MAX_FAVORITE_NUMBERS][MAX_MSISDN_BLEN];	
	u_char		last_call_type;
	u_long		last_call_date;
	u_char		last_call_number[MAX_MSISDN_BLEN];
	
	/*following fields are designed for cap CALL/SMS,Pierre, 2007-07-13 */
	
	double		in_net_cap_sms_balance;
	u_short		in_net_cap_sms_counter;
	double		out_net_cap_sms_balance;
	u_short		out_net_cap_sms_counter;
	
	double		in_net_cap_call_balance;
	u_long		in_net_cap_call_duration;
	double		out_net_cap_call_balance;
	u_long		out_net_cap_call_duration;

	double		call_in_cap_balance;
	u_long		call_in_cap_duration;

	double		in_net_cap_balance;
	double		out_net_cap_balance;

	long long	      gprsVolume;	
	long long	      gprsVolumeThisMonth;
	double	      gprsBalance;
	u_short	      gprsNotificationTimes;
	
	u_char	      freeSMSActiveDays;

	UserData_Pool_Account	poolAccount;
	
	u_char	callMeBackRequestTimes;
	u_char	favorite_plan_id;	/* 0=default, not plan user, 1-6=index0-5*/
	u_char	favorite_plan_state;      /* 0=ok, 1=suspended */
	u_char	cap_sms_notify_counter;
    	u_char	cReseverd[3];
	u_long	free_favorite_call;   /* in seconds */    	
	u_long	free_favorite_sms;
	double	dReserved[2]; 

	_bundle_info	bundle_info;
#ifdef OCS_WITH_CRM
	_crm_info	crm_info;
#endif
} _prepaid_info;

#define INVALID_UE_INDEX	0xFFFFFFFF 


#define UNIT_STORE_ACCOUNT	100
#define MSISDN_HEAD_NUM		600 //1000
#define MAX_SUBS_RECORD		(MSISDN_HEAD_NUM*UNIT_STORE_ACCOUNT)

typedef struct prepaid_data_old{
	long long			msisdn_head[MSISDN_HEAD_NUM];	
	_prepaid_info_old	prepaid_info[MSISDN_HEAD_NUM][UNIT_STORE_ACCOUNT];
} _prepaid_data_old;

typedef struct prepaid_data {
	long long			msisdn_head[MSISDN_HEAD_NUM];		
    _prepaid_info       prepaid_info[MSISDN_HEAD_NUM][UNIT_STORE_ACCOUNT];
} _prepaid_data;


#define MAX_CARD_HRN_BLEN		8   
#define MAX_CARD_HRN_ALEN		16   
#define MAX_CARD_SEGMENT		2000
#define MAX_CARD_NUM_PSEG		100
#define MAX_CARD_RECORD		(MAX_CARD_SEGMENT*MAX_CARD_NUM_PSEG)
#define MAX_CARD_LENGTH		10
#define MAX_CUG_ID				10000
#define NOT_CUG_ACCOUNT		0

#define CARD_TAIL_LEN			2

#define MAX_VALUE_TYPE			8

#define _RCI_ _recharge_card_info
#define _recharge_card _recharge_card_info

typedef enum CARD_STATUS{
   CARD_FRESH,
   CARD_USED,
   CARD_SUSPEND,
   CARD_LONG_TIME_NOT_USED,
   CARD_AS_CC_USED,
}_CARD_STATUS;

typedef struct {
	u_char		card_no[MAX_CARD_LENGTH+1];   /* 'E' fill at the end  */
	u_char		card_pwd[MAX_CARD_HRN_BLEN+1];         
	long		face_value;   
	u_char		card_status;
	u_long		expiry_date;
	u_short		valid_time;
	char		msisdn_used[18];
	u_long		updated_date; 
} _recharge_card_info;

typedef struct card_data{
 	long		face_value[MAX_VALUE_TYPE];
	u_char		segment_used_flag[MAX_CARD_SEGMENT];
	long long	prepaid_card_head[MAX_CARD_SEGMENT];
    _recharge_card_info  prepaid_card[MAX_CARD_SEGMENT][MAX_CARD_NUM_PSEG];
}_card_data;
 
#define BILLING_BASE_NUM		1024     /* number used by billing */
#define MAX_DISCOUNT_ID		32
#define MAX_ZONE_NUM_OLD		16
#ifdef _MAX_64COS_COOK_
#define MAX_ZONE_NUM			64// used in Cook island, Diego
#else
#define MAX_ZONE_NUM			16// used for PNCC etc
#endif
#define MAX_RENT_TARIFF		8
#define CALLED_BASE_NUM		50
#define MAX_MO_CALLTYPE		5
#define MAX_MT_CALLTYPE		4
#define	MAX_SMS_PREFIX		50
#define TARIFF_PREFIX_LEN		16

#define	MAX_GPRS_PREFIX			1

#define	MAX_VAS_MMS_SEND_TARIFF					64
#define	MAX_VAS_MMS_RETRIEVE_TARIFF				1
#define	MAX_VAS_MMSEMAIL_DELIVER_TARIFF			1


#define COS_GROUP_NUM			16
#define MAX_ZONE_NUM_NEW		(MAX_ZONE_NUM/COS_GROUP_NUM)

/*
Charge on receiving call is not defined , 2003-10-10
*/

typedef struct comm_tariff
{
   u_short		cfChargeUnit; /* call forward */
   float		cfChargeAmount;
   u_short		roamingChargeUnit;  /* roaming within province */
   float		roamingChargeAmount; /* roaming within province */
   u_short		cugChargeUnit;
   float		cugChargeAmount;
   u_short		ccChargeUnit;  /*conference call */
   float		ccChargeAmount;
   float		favEditChargeAmount;   
   u_short		favChargeUnit; /* favorite number call */
   float		favChargeAmount; 
   u_short		cf_cugChargeUnit; /* call forward + cug */
   float		cf_cugChargeAmount;
   u_short		cf_favChargeUnit; /* call forward + favorite number */
   float		cf_favChargeAmount;
   u_short		cug_favChargeUnit; /* cug + favorite number */
   float		cug_favChargeAmount;
   u_short		cf_cug_favChargeUnit; /* call forward + cug + favorite number */
   float		cf_cug_favChargeAmount; 
   
   	float	   	childChangeChargeAmount;
	u_short   	poolAccountChargeUnit; 
	float 	   	poolAccountChargeAmount; 
	float	   	activeFreeSMSCharegeAmount;
	float	   	deactiveFreeSMSCharegeAmount;
}_comm_tariff;


typedef struct _TIER_INFO{
	u_long	units;
	float		base_fee;
	float		long_distance_fee;
}TIER_INFO;

#define		MAX_TIER		3
#define		TARIFF_AREA_LEN 31

typedef struct{
	u_char 		tierNumber;
	TIER_INFO	rating[MAX_TIER];
}TIER_RATING;

typedef struct bill_tariff {
	char			bill_id[TARIFF_PREFIX_LEN+1];
	char			area[TARIFF_AREA_LEN];
	char			cap_flag;
	u_char		call_type;
 	u_char		tariffID;
	u_char		discountID;
	u_char		free_time; /*0-240 seconds*/
	u_short		unit_time;
	u_char		mini_unit;	
	float			adjustment;
	TIER_RATING	tierRating;
} _bill_tariff; 

typedef struct rent_tariff {
	u_char	id;  /* from 0-15 */
	char		description[16];
	u_char	rent_type;  /*0: daily, 1: monthly */
	u_char	charge_date; /* monthly day : 1-28*/ 
 	float	rent_amount;
} _rent_tariff;

typedef struct bill_discount 
{
	u_char discount_id;
	u_char hours;
	u_char days[8];
} _bill_discount;

typedef struct bill_holiday 
{
	u_char month;
	u_char day;
	u_char mflag;
} _bill_holiday;

#define DEFAULT_MT_BILLING 0
#define	DEFAULT_SMS_BILLING 0

typedef struct bill_sms
{
	u_char		id;
	char			bill_id[TARIFF_PREFIX_LEN+1];
	u_char		call_type;
	char			area[31];
	char			cap_flag;
	u_char		tariffID;
	u_char		discountID;
	float			base_fee;
}_bill_sms;

typedef struct gprs_tariff {
	u_char			tariffID;
	u_char			gprsID;
	ulong			destIp;
	u_short			chargeUnit;		/*	KB */
	float				basicFee;
	u_short			miniChargeUnit;/*	KB	*/
	u_short			initialAdjustment;	
	char				cap_flag;
	u_char			discountID;	
	u_char			reserved[32];
} _gprs_tariff; 


typedef struct _VAS_MMS_SEND_TARIFF{
	u_char		tariffID;
	u_char		mmsSendID;
	u_char		mmsType;
	u_char		prefix[128];
	u_char		callType;
	u_char		destName[128];
	u_char		discountID;
	float		chargeFee;
	u_char		capFlag;
	u_char		reserved[32];
}VAS_MMS_TARIFF;


typedef struct _VAS_MMS_RETRIEVE_TARIFF{
	u_char		tariffID;
	u_char		mmsRetrieveID;
	u_char		prefix[128];
	u_char		callType;
	u_char		destName[128];
	u_char		discountID;
	float			chargeFee;
	u_char		capFlag;
	u_char		reserved[32];
}VAS_MMS_RETRIEVE_TARIFF;


typedef struct _VAS_MMSEMAIL_RETRIEVE_TARIFF{
	u_char		tariffID;
	u_char		emailID;
	u_char		prefix[128];
	u_char		callType;
	u_char		destName[128];
	u_char		discountID;
	float		chargeFee;
	u_char		capFlag;
	u_char		reserved[32];
}VAS_MMSEMAIL_DELIVER_TARIFF;


typedef struct _VAS_TARIFF{
	VAS_MMS_TARIFF					vasMmsSendTariff[MAX_VAS_MMS_SEND_TARIFF];
	VAS_MMS_RETRIEVE_TARIFF		vasMmsRetrieveTariff[MAX_VAS_MMS_RETRIEVE_TARIFF];
	VAS_MMSEMAIL_DELIVER_TARIFF		vasMmsEmailDeliverTariff[MAX_VAS_MMSEMAIL_DELIVER_TARIFF];	
}VAS_TARIFF;

typedef struct base_tariff {
	char			bill_id[TARIFF_PREFIX_LEN+1];
	char			area[TARIFF_AREA_LEN];
	u_char		call_type;
} _base_tariff; 


typedef struct tariff_data_old {
	_comm_tariff			comm_tariff[MAX_ZONE_NUM_OLD];
	_rent_tariff			rent_tariff[MAX_ZONE_NUM_OLD][MAX_RENT_TARIFF];
	_bill_tariff			bill_tariff[MAX_ZONE_NUM_OLD][BILLING_BASE_NUM];
	_bill_tariff			called_tariff[MAX_ZONE_NUM_OLD][CALLED_BASE_NUM];
	_bill_discount			bill_discount[MAX_DISCOUNT_ID][24]; /* id=9 for sms */
	_bill_holiday			holiday_flag[12][31];
	_bill_sms				bill_sms[MAX_ZONE_NUM_OLD][MAX_SMS_PREFIX];
} _tariff_data_old;

typedef struct tariff_data {
	_comm_tariff			comm_tariff[MAX_ZONE_NUM];
	_rent_tariff			rent_tariff[MAX_ZONE_NUM][MAX_RENT_TARIFF];
	_bill_tariff			bill_tariff[MAX_ZONE_NUM][BILLING_BASE_NUM];
	_bill_tariff			called_tariff[MAX_ZONE_NUM][CALLED_BASE_NUM];
	_bill_discount			bill_discount[MAX_DISCOUNT_ID][24]; /* id=9 for sms */
	_bill_holiday			holiday_flag[12][31];
	_bill_sms				bill_sms[MAX_ZONE_NUM][MAX_SMS_PREFIX];
	_gprs_tariff			gprs_tariff[MAX_ZONE_NUM][MAX_GPRS_PREFIX];
	VAS_TARIFF			vas_tariff[MAX_ZONE_NUM];
	_base_tariff			base_tariff[BILLING_BASE_NUM];
} _tariff_data;
/*---------*/

typedef struct pps_free_index
{
	int	user_counter; /* account counter */
	int	pWriteSub;
	u_char	status[MAX_SUBS_RECORD];
	int	free_memory[MAX_SUBS_RECORD];
}_pps_free_index;

typedef struct pps_index_node
{
	long long	key;
	int		store_index;
}_pps_index_node;

typedef	struct pps_index_table
{
	_pps_index_node		prim_index[MAX_SUBS_RECORD];
}_pps_index_table;
/* index table is part of shm memory , and sync. between 2 plans */

typedef struct pps_index_db
{
	_pps_free_index		free_index;
	_pps_index_table	index_table;
}_pps_index_db;

typedef struct _ram_data_old{
	_tariff_data_old	tariff_data;
	_card_data		card_data;  
	_prepaid_data		prepaid_data;
	_pps_index_db	index_data;
} _ram_data_old;

typedef struct _ram_data{
	_tariff_data		tariff_data;
	_card_data		card_data;  
	_prepaid_data		prepaid_data;
	_pps_index_db	index_data;
} _ram_data;

/* all data should be divided into 3 files:
tariff
recharge_card
account
*/



#endif  /* RAMDATA__H */ 

