#pragma once

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

#include "blitz/protocol/Protocol.h"

namespace blitz {
namespace protocol {

/**
 * \class DisconnectPacket
 * \brief Packet for disconnecting from the server.
 * %Packet structure :
 * |      PacketType 		|
 * |------------------------|
 * | PacketType::Disconnect	|
 *
 * |	 Field Name 	|  	 Field Type		|  			  Notes 			|
 * |--------------------|-------------------|-------------------------------|
 * |	m_Reason		|    std::string  	|  The reason for disconnection	|
 */
class DisconnectPacket : public Packet {
  private:
	std::string m_Reason;  // only when sent from server
  public:
	/**
	 * \brief Default constructor.
	 */
	DisconnectPacket() {}
	/**
	 * \brief Constructor.
	 * \param reason The reason for disconnection.
	 */
	DisconnectPacket(std::string reason) : m_Reason(reason) {}
	virtual ~DisconnectPacket() {}

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

	/**
	 * \brief Get the reason for disconnection.
	 * \return The reason for disconnection.
	 */
	const std::string& GetReason() const {
		return m_Reason;
	}

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

}  // namespace protocol
}  // namespace blitz
