#include <UniqueID/UniqueID.hpp>

extern "C"
{
#ifdef _WIN32
#include <Rpc.h>
#else
#include <uuid/uuid.h>
#endif
}

bool UniqueID::operator==(const UniqueID &other) const
{
    return std::memcmp(data, other.data, sizeof(data)) == 0;
}

UniqueID UniqueID::generate()
{
    UniqueID result;

#ifdef _WIN32
    UuidCreate ( (UUID*) result.data );
#else
    uuid_generate_random(result.data);
#endif

    return result;
}

std::ostream& operator<<(std::ostream &os, UniqueID id)
{
#ifdef _WIN32
    unsigned char *str;
    UuidToStringA((UUID*) id.data, &str);
    os << (char*) str;
    RpcStringFreeA(&str);
#else
    char str[37];
    uuid_unparse(id.data, str);
    os << str;
#endif

    return os;
}