#pragma once

/**
 * \file ChatPacket.h
 * \brief File containing the blitz::protocol::ChatPacket class
 */

#include "blitz/maths/Vector.h"
#include "blitz/protocol/Protocol.h"
#include <vector>

namespace blitz {
namespace protocol {

/**
 * \struct ColoredPart
 * \brief Represents a part of a chat message with a specific color.
 */
struct ColoredPart {
	/**
	 * \brief The color of the part.
	 */
	Vec4f color;
	/**
	 * \brief The text of the part.
	 */
	std::string text;
};

typedef std::vector<ColoredPart> ColoredText;

/**
 * \class ChatPacket
 * \brief Packet for sending chat messages.
 * %Packet structure :
 * |      PacketType 		|
 * |------------------------|
 * | PacketType::Chat	|
 *
 * |	 Field Name 	|  	 Field Type		|  			  Notes 			|
 * |--------------------|-------------------|-------------------------------|
 * |	m_Message		|    ColoredText  	|  The message sent in the chat	|
 */
class ChatPacket : public Packet {
  private:
	ColoredText m_Message;

  public:
	/**
	 * \brief Default constructor.
	 */
	ChatPacket() {}
	/**
	 * \brief Constructor.
	 * \param msg The message to send.
	 */
	ChatPacket(const std::string& msg) : m_Message(ColorizeText(msg)) {}
	/**
	 * \brief Constructor.
	 * \param msg The message to send.
	 */
	ChatPacket(const ColoredText& msg) : m_Message(msg) {}
	virtual ~ChatPacket() {}

	virtual DataBuffer Serialize(bool packetID = true) const;
	virtual void Deserialize(DataBuffer& data);
	virtual void Dispatch(PacketHandler* handler) const;

	/**
	 * \brief Get the message.
	 * \return The message.
	 */
	const ColoredText& GetMessage() const {
		return m_Message;
	}

	virtual PacketType GetType() const {
		return PacketType::Chat;
	}

	/**
	 * \brief Get the text color.
	 */
	static std::string GetTextColor(Vec3uc color);
	/**
	 * \brief Colorize a text.
	 */
	static ColoredText ColorizeText(const std::string& text);
	/**
	 * \brief Get the colored text string.
	 */
	static std::string GetColoredTextString(const ColoredText& text);
};

const static Vec3uc AQUA = {0, 255, 255};
const static Vec3uc BLUE = {0, 0, 255};
const static Vec3uc GREEN = {0, 255, 0};
const static Vec3uc PURPLE = {255, 0, 255};
const static Vec3uc RED = {255, 0, 0};
const static Vec3uc WHITE = {255, 255, 255};
const static Vec3uc YELLOW = {255, 255, 0};

}  // namespace protocol
}  // namespace blitz
