#ifndef OPENMW_MISCELLANEOUSAPI_HPP
#define OPENMW_MISCELLANEOUSAPI_HPP

#include "../Types.hpp"

#define MISCELLANEOUSAPI \
    {"GenerateRandomString",        MiscellaneousFunctions::GenerateRandomString},\
    \
    {"GetSHA256Hash",               MiscellaneousFunctions::GetSHA256Hash},\
    \
    {"GetLastPlayerId",             MiscellaneousFunctions::GetLastPlayerId},\
    \
    {"GetCurrentMpNum",             MiscellaneousFunctions::GetCurrentMpNum},\
    {"SetCurrentMpNum",             MiscellaneousFunctions::SetCurrentMpNum}

class MiscellaneousFunctions
{
public:

    /**
    * \brief Generate a random string of a particular length that only contains
    *        letters and numbers.
    *
    * \param length The length of the generated string.
    * \return The generated string.
    */
    static const char *GenerateRandomString(unsigned int length) noexcept;

    /**
    * \brief Get the SHA256 hash corresponding to an input string.
    * \details function is not reentrant due to a static variable
    *
    * \param inputString The input string.
    * \return The SHA256 hash.
    */
    static const char *GetSHA256Hash(const char* inputString) noexcept;

    /**
    * \brief Get the last player ID currently connected to the server.
    * \details function is not reentrant due to a static variable
    *
    * Every player receives a unique numerical index known as their player ID upon joining the
    * server.
    *
    * \return The player ID.
    */
    static unsigned int GetLastPlayerId() noexcept;

    /**
    * \brief Get the current (latest) mpNum generated by the server.
    *
    * Every object that did not exist in an .ESM or .ESP data file and has instead been placed or
    * spawned through a server-sent packet has a numerical index known as its mpNum.
    *
    * When ObjectPlace and ObjectSpawn packets are received from players, their objects lack mpNums,
    * so the server assigns them some based on incrementing the server's current mpNum, with the
    * operation's final mpNum becoming the server's new current mpNum.
    *
    * \return The mpNum.
    */
    static int GetCurrentMpNum() noexcept;

    /**
    * \brief Set the current (latest) mpNum generated by the server.
    *
    * When restarting a server, it is important to revert to the previous current (latest) mpNum
    * as stored in the server's data, so as to avoid starting over from 0 and ending up assigning
    * duplicate mpNums to objects.
    *
    * \param mpNum The number that should be used as the new current mpNum.
    * \return void
    */
    static void SetCurrentMpNum(int mpNum) noexcept;
};

#endif //OPENMW_MISCELLANEOUSAPI_HPP