/***************************************************************************
 *   Copyright (C) 2004 by yunfan                                          *
 *   yunfan_zg@163.com                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef LIBEVAFRIEND_H
#define LIBEVAFRIEND_H

#include "evapacket.h"
#include "evadefines.h"
#include <list>
#include <string>

class FriendItem{
public:
	FriendItem() {};
	FriendItem(const unsigned char *buf, int *len);
	FriendItem(const FriendItem &rhs);
	~FriendItem() {}
	
	const int getQQ() const { return qqNum; }
	const char getFace() const { return face; }
	const char getAge() const { return age; }
	const char getGender() const { return gender; }
	const std::string &getNick() const { return nick; }  // note: nick is encoded by "GB/GBK"
	const char getExtFlag() const { return extFlag; }
	const char getCommonFlag() const { return commonFlag; }
	const long getLoginTime() const { return loginTime; }
	const long getIdleTime() const { return idleTime; }
	const long getLastRefreshTime() const { return lastRefreshTime; }
	
	bool isMember() { return (commonFlag & 0x2) != 0; }
	bool isBoy() { return gender == QQ_FRIEND_GENDER_GG;}
	FriendItem *copy() { return new FriendItem(*this);}
	FriendItem &operator=(const FriendItem &rhs);
private:
	void parseData(const unsigned char *buf, int *len);
	 
	int qqNum;
	char face;
	char age;
	char gender;
	std::string nick;	
	char extFlag;  // bit1: if has qqshow, the rest are unknown  
	char commonFlag;  //  bit1: memeber,   bit4: TCP mode,   bit5 : mobile QQ, 
			  //  bit6: mobile binding,   bit7: webcam
	long loginTime;
	long idleTime;
	long lastRefreshTime;
};

typedef std::list<FriendItem> friendItemList;

class GetFriendListPacket : public OutPacket {
public:
	GetFriendListPacket();
	GetFriendListPacket(const short startPosition);
	GetFriendListPacket(const GetFriendListPacket &rhs);
	virtual ~GetFriendListPacket() {};
	
	OutPacket * copy() { return new GetFriendListPacket(*this);}
	GetFriendListPacket &operator=( const GetFriendListPacket &rhs);
	
	const short getStartPosition() const { return startPosition; }
	void setStartPosition(const short startPosition) { this->startPosition = startPosition; }

protected:
	virtual int putBody(unsigned char *buf) ;

private:
	short startPosition;            
};

class GetFriendListReplyPacket : public InPacket {
public:
	GetFriendListReplyPacket() {}
	GetFriendListReplyPacket(unsigned char *buf, int len);
	GetFriendListReplyPacket(const GetFriendListReplyPacket &rhs);
	virtual ~GetFriendListReplyPacket() {}
	
	const short getPosition() const { return position; }
	const friendItemList &getFriendList() const { return friends; }
	GetFriendListReplyPacket &operator=( const GetFriendListReplyPacket &rhs);
protected:
	void parseBody();
private:
	short position;
	friendItemList friends;
};

#endif

