#include "UID.h"
#include <random>
#include <sstream>
#include <iomanip>

static int nextID = 0;

std::string GenerateUUID() {

    std::ostringstream ss;
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<int> dis(0, 15);
    std::uniform_int_distribution<int> dis2(8, 11);

    for (int i = 0; i < 32; i++) {
        if (i == 12)
            ss << 4;
        else if (i == 16)
            ss << dis2(gen);
        else
            ss << std::hex << dis(gen);
    }
    return ss.str();
}

UID::UID()
    : id(nextID++), uuid(GenerateUUID()) {}

UID::UID(int id, const std::string& uuid)
    : id(id), uuid(uuid) {}
