#pragma once

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

#include "blitz/protocol/Protocol.h"

namespace blitz {
namespace protocol {

/**
 * \class ServerTpsPacket
 * \brief Packet for sending server TPS (Tick per second) and MSPT (Milliseconds per tick).
 * %Packet structure :
 * |      PacketType 		|
 * |------------------------|
 * | PacketType::ServerTps	|
 *
 * |	 Field Name 	|  	 Field Type		|  			  Notes 			|
 * |--------------------|-------------------|-------------------------------|
 * |		Tps			|  		float		|  Server TPS					|
 * |		Mspt		|  		float		|  Server MSPT					|
 * | 	PacketSendTime  |     uint64_t		|  Time the packet was sent		|
 */
class ServerTpsPacket : public Packet {
  private:
	float m_TPS;
	float m_MSPT;
	std::uint64_t m_PacketSendTime;	 // used to calculate ping
  public:
	/**
	 * \brief Default constructor.
	 */
	ServerTpsPacket() {}
	/**
	 * \brief Constructor.
	 * \param tps The server TPS.
	 * \param mspt The server MSPT.
	 * \param sendTime The time the packet was sent.
	 */
	ServerTpsPacket(float tps, float mspt, std::uint64_t sendTime) : m_TPS(tps), m_MSPT(mspt), m_PacketSendTime(sendTime) {}
	virtual ~ServerTpsPacket() {}

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

	/**
	 * \brief Get the server TPS.
	 * \return The server TPS.
	 */
	float GetTPS() const {
		return m_TPS;
	}

	/**
	 * \brief Get the server MSPT.
	 * \return The server MSPT.
	 */
	float GetMSPT() const {
		return m_MSPT;
	}

	/**
	 * \brief Get the time the packet was sent.
	 * \return The time the packet was sent.
	 * \todo Calculate ping.
	 */
	std::uint64_t GetPacketSendTime() const {
		return m_PacketSendTime;
	}

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

}  // namespace protocol
}  // namespace blitz
