#include "PlayerSessionRegistry.hpp"
#include "PlayerSession.hpp"

namespace tw::net {

SessionId PlayerSessionRegistry::generate_session_id() {
    static SessionId next_id = 1;
    return next_id++;
}

SessionId PlayerSessionRegistry::register_session(msg::PeerId peer, msg::MessageConnection* connection) {
    const SessionId session_id = generate_session_id();

    auto session = std::make_unique<PlayerSession>(session_id, connection);
    m_session_vec.emplace_back(session.get());

    m_session_map.emplace(session_id, std::move(session));
    m_peer_sessions.emplace(peer, session_id);

    return session_id;
}

}
