#ifndef CHAT_MESSAGE
#define CHAT_MESSAGE

#include <string>
#include "softProj\commonTypes.h"

/// Represents buddy that user can chat with.
/** Represents buddy that user can chat with. Buddy is actually some fortress in a game, because user
communicates with fortresses, not other users (although it is user of course who controls that fortress and 
gets messages and responses, but point is, that user can communicate with more ships with some user. 
It has private constructor and two factory methods, because we only want to create messages of two types, 
incoming or outgoing, that differs in a way that incoming has timestamp set by server, while outgoing does not, 
because it will arrive to server and then it gets timestamp.
*/
class ChatBuddy {
public:
	ChatBuddy(int id, const std::string & name);

	/** Gets buddy id. 
	This identifier is actually identifier of some fortress in a game.
	@return Buddy id
	*/
	int getId();

	/** Gets buddy name
	This name is actually name of some fortress in a game.
	@return Buddy name
	*/
	std::string & getName();
private:
	int id_;
	std::string name_;
};

/// Represents message that is received or sent in chat conversation.
/** Represents message that is received or sent in chat conversation. Message always have id of target 
buddy and actual text of a message. There are two types of messages. Incoming, these are messages that user
receives from other buddy, and outgoing, these are messages that user wants to sent to other buddy .
If it is incoming, it also have a timestamp set by server that means the time when message arrived to the server
from sender when sending to the receiver. In case of outgoing message, timestamp is empty, because server will
take care of setting it correctly when it accepts the message.
*/
class ChatMessage
{
public:
	/** Gets id of target buddy, that is buddy, that is this message addressed
	@return Id of target buddy
	*/
	id_t getBuddyId();

	/** Gets actual text of a message
	@return Actual text of a message
	*/
	std::string & getText();
	
	/** Gets timestamp of a message, that is a time, when it arrived to server.
	This value is setted by server when message arrives to him. So when message is 
	send, it is empty, than server sets the value and when receiver gets message, the
	timestamp is set.
	@return Message timestamp
	*/
	std::string & geTimeStamp();

	/** Crates new instance of ChatMessage as an outgoing message.
	Outgoing message does not have real timestamp, because server will set it when
	message arrives to him.
	@param buddyId Id of target buddy
	@param text Actual text of a message
	*/
	static ChatMessage * createOutgoingMessage(id_t buddyId, const std::string & text);

	/** Crates new instance of ChatMessage as an incoming message.
	Outgoing message has real timestamp, because server set it when
	message arrived to him.
	@param buddyId Id of target buddy
	@param text Actual text of a message
	@param timeStamp Timestamp when message arrived to the server
	*/
	static ChatMessage * createIncomingMessage(id_t buddyId, const std::string & text, const std::string & timeStamp);

	/** Gets if message is incoming 
	@return True if message is incoming, false otherwise
	*/
	bool isIncoming();

	/** Gets if message is outgoing 
	@return True if message is outgoing, false otherwise
	*/
	bool isOutgoing() ;
private:
	enum EChatMessageType {
		INCOMING_CHAT_MESSAGE, OUTGOING_CHAT_MESSAGE
	};

	id_t buddyId_;
	std::string text_;
	EChatMessageType type_;
	std::string timeStamp_;

	ChatMessage(EChatMessageType type, id_t buddyId, const std::string & text, const std::string & timeStamp) {
		this->buddyId_ = buddyId;
		this->text_ = text;
		this->type_ = type;
		this->timeStamp_ = timeStamp;
	}
};

#endif