#pragma once

#include "ChatService.hpp"
#include "ProtobufMessages.hpp"
#include "message_protocol/MessageEndpoint.hpp"

#include <cstdint>
#include <memory>

namespace tw::chat {

class ChatServerController {
    std::unique_ptr<msg::MessageEndpoint> m_endpoint;
    ProtobufMessages                      m_messages;
    ChatService                           m_service;

public:
    explicit ChatServerController(int port = CHAT_DEFAULT_PORT);

    void update();

private:
    void register_handlers();
    void broadcast(msg::PeerId client_id, const ChatMessage& msg);
};

} // namespace tw::chat
