#ifndef _PRECARD_H
#define _PRECARD_H

#include "ramdata.h"

#define		MAX_USED_CARD_STORED		8192
#define		MAX_CLIMAX_CARD_SEGMENT		50 /* 5000 cards stored */
#define		MAX_PREPAID_CARD_NUM		(MAX_CARD_SEGMENT*MAX_CARD_NUM_PSEG)

typedef struct USED_PREPAID_CARD_BUFFER{
   int		ptrHead;
   int		ptrTail;
   _recharge_card_info  used_precard[MAX_USED_CARD_STORED];
}_USED_REPAID_CARD_BUFFER;

typedef struct free_mem_quence
{
//	int	front_ptr;
//	int	rear_ptr;
	int	pWriteSub;
	int	free_pos[MAX_PREPAID_CARD_NUM+1];
}_free_mem_quence;

typedef struct climax_quence
{
	int		counter;
	int		store_pos[MAX_PREPAID_CARD_NUM];
	int		store_pos_card_no[MAX_PREPAID_CARD_NUM];
	u_char		card_pwd[MAX_PREPAID_CARD_NUM][MAX_CARD_HRN_BLEN];
	long long	card_no[MAX_PREPAID_CARD_NUM];
}_climax_quence;

typedef struct card_index
{
	_free_mem_quence free_quence;
	_climax_quence      card_quence;
}_card_index;

typedef enum SCF_RCM_OC
{
	OC_NULL,
	OC_UPDATE_CARD,
	OC_UPDATE_CARD_ACK,
}_SCF_RCM_OC;

typedef enum SCF_RCM_RESULT
{
	OC_RESULT_OK,
	OC_RESULT_NO_CARD,
	OC_RESULT_CARD_USED,
	OC_RESULT_CARD_EXPIRED,
	OC_RESULT_SYSTEM_FAILURE,
}_SCF_RCM_RESULT;

typedef struct scf_rcm_msg{
	u_short	invoke_id;
	u_char	ocode;
	u_char	result;
	u_char	card_pwd[MAX_CARD_HRN_BLEN];
	char		msisdn[32];
	_recharge_card_info card_data;
}_scf_rcm_msg;

int  StorePrepaidCard(int *head_no, int head);
int  InquiryPrepaidCardStorePos(long long head);
void CardHeadInDecrement(int flag);
void CardNumberInDecrement(int flag);
int  ImportPrepaidCardData(char *carddata);
int  RechargeCardRequest(u_short proc_id,char *card_hrn,int *result);
int  SendPrepaidCardRealSync(int instance,int ocode);
int  UpdateRechargeCard(u_short proc_id, int status);
int  SetPrepaidCardByOMC(u_char oidlen, DWORD *oid, u_char *pdata, u_short datalen);
int  GetUsedPrepaidCard(u_char oidlen, DWORD *oid, u_char *pdata, BYTE *vartype);
int  SetPrepaidCardFaceValue(long face_value);
void MoveUsedCardToBuffer(int instance);
void DeletePrepaidCardHead(int cardhead);

float ocs_get_calling_card_left_balance(int head, int tail);
int UpdateRechargeCardBalance(_card_info *cardshmp, float charge);

#endif 

