#pragma once
#include <myapp/rcon/peerprovider.h>
#include <myapp/logging/logger.h>
#include <list>
#include <memory>
#include <string>

namespace myapp::rcon {

class server final
{
public:
    explicit server(std::shared_ptr<logging::logger>, std::unique_ptr<peer_provider>);
    void start(std::string endpoint);
    void publish(std::string);
    void set_on_data(std::function<std::string(std::string)>) noexcept;

private:
    void on_data(connection&, std::string);
    void on_accept(std::unique_ptr<connection>);
    void on_closed(connection&);
    void on_error(std::string);

private:
    std::shared_ptr<logging::logger> logger_;
    std::unique_ptr<peer_provider> peerProvider_;
    std::list<std::unique_ptr<connection>> clients_;
    std::function<std::string(std::string)> data_handler_;
};

} /* namespace myapp::rcon */
