#include "quicr/QuicrConnectionListener.hpp"
#include "quicr/QuicrEndpoint.hpp"

#include <spdlog/spdlog.h>

namespace tw::net::quicr {

QuicrConnectionListener::QuicrConnectionListener(QuicrEndpoint* endpoint)
    : m_listened_connections()
{
    endpoint->assign_listener(this);
}

tl::expected<std::unique_ptr<QuicrConnectionListener>, QuicrError> QuicrConnectionListener::listen(QuicrEndpoint* endpoint) {
    return std::unique_ptr<QuicrConnectionListener>(new QuicrConnectionListener(endpoint));
};

QuicrConnection* QuicrConnectionListener::listen() {
    if(m_listened_connections.size() > 0) {
        QuicrConnection* connection = m_listened_connections.front();
        m_listened_connections.pop_front();

        return connection;
    }

    return nullptr;
}

}
