/***************************************************************************
 *   Copyright (C) 2005 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 LIBEVAQUNLIST_H
#define LIBEVAQUNLIST_H
#include "evaqun.h"
#include "evafriend.h"
#include <list>
#include <map>

/*
         this file is for holding all Qun information for a user
*/

// TempQun is only for temporary Qun

class TmpQun{
public:
	TmpQun();  // this constructor is for create TmpQun only
	TmpQun(const int pid);
	
	TmpQun &operator=(const TmpQun &rhs);
	
	void setQunID(const int id) { qunID = id; }
	void setParentID(const int id) { parentID = id; }
	void setName(const std::string &n) { name = n; }
	// set all members at one go
	void setMemberList(const std::list<int> &list) { memberList = list; }
	
	void addMember(const int qqNum); // add one more member
	const bool removeMember(const int qqNum);
	
	const int getQunID() const { return qunID; }
	const int getParentID() const { return parentID; }
	const std::string &getName() const { return name; }
	const std::list<int> &getMemberQQList() const { return memberList; }
private:
	int qunID;
	int parentID;
	std::string name;
	std::list<int> memberList; // all member details are in its parent
};

// Qun is only for permenant Qun
class Qun{
public:
	/*
	* constructor for Qun
	*@param id   internal ID of a Qun
	*/
	Qun(const int id);
	enum MessageType{Notify, Popup, Numbers, RecordOnly, Reject};
	Qun &operator=(const Qun &rhs);
	const int getQunID() const { return qunID; }
	const QunInfo &getDetails() const { return info; }
	const std::list<FriendItem> &getMembers() const { return memberList; }
	const FriendItem *getMemberDetails(const int qqNum);
	
	void setDetails(const QunInfo &info) { this->info = info; }
	
	void setMember(const FriendItem &fi);
	void setMembers(const std::list<FriendItem> &list);

	void updateOnlineMembers(const std::list<int> &list);
	
	void setQQList(const std::list<int> &list) { numberList = list; }
	const std::list<int> getQQList() const { return numberList; }
	
	void setMemberArgs(const std::map<int, QunMember> &list);
	const bool isAdmin( const int id);
	
	const int numMembers() const { return memberList.size(); }
	
	void setCardName(const std::string n) { cardName = n; }
	void setCardGender(const unsigned char g ) { cardGender = g; }
	void setCardPhone(const std::string p) { cardPhone = p; }
	void setCardEmail(const std::string e) { cardEmail = e; }
	void setCardMemo(const std::string m) { cardMemo = m; }
	
	const std::string &getCardName() const { return cardName; }
	const unsigned char &getCardGender() const { return cardGender; }
	const std::string &getCardPhone() const { return cardPhone; }
	const std::string &getCardEmail() const { return cardEmail; }
	const std::string &getCardMemo() const { return cardMemo; }
	
	void setMessageType(const MessageType type) { msgType = type; }
	const MessageType getMessageType() const { return msgType; }
	
	const std::list<TmpQun> &getTmpQunList() const { return tmpQunList; }
	void addTmpQun(const TmpQun &q);
	
	const bool hasTmpQun() const { return tmpQunList.size() != 0; }
	
	const bool hasMember(const int id);
private:
	int qunID;
	QunInfo info;
	std::list<int> numberList;
	std::map<int, QunMember> memberArgs;
	std::list<FriendItem> memberList;
	std::list<TmpQun> tmpQunList;
	
	// my Qun card information
	std::string cardName;
	unsigned char cardGender;
	std::string cardPhone;
	std::string cardEmail;
	std::string cardMemo;
	
	MessageType msgType;
};

class QunList {
public:
	QunList() {};
	
	QunList &operator=(const QunList &rhs);
	void add(const Qun &q);
	bool remove(const int id);
	void update(const Qun &q);
	Qun *getQun(const int id);
	
	void setDetails(const QunInfo &info);
	void setMember(const int id, const FriendItem &fi);
	void setMembers(const int id, const std::list<FriendItem> &list);
	
	void setOnlineMembers(const int id, const std::list<int> &list);
	
	void setQQList(const int id, const std::list<int> &list);
	void setMemberArgs(const int id, const std::map<int, QunMember> &member);
	
	const std::list<Qun> &getQunList() const { return qunList; }
	void clearQunList() { qunList.clear(); }
	
	void setMyQunCardInfo(const int id, const std::string name, const unsigned char gender, const std::string phone,
				const std::string email, const std::string memo);
	const int numQuns() const { return qunList.size(); }
private:
	std::list<Qun> qunList;
};

#endif
