#pragma once
#include <myapp/rcon/peerprovider.h>
#include <myapp/async/eventloop.h>
#include <myapp/async/pipe.h>
#include <memory>
#include <string>

namespace myapp::rcon {

class unix_provider final : public peer_provider
{
public:
    static std::unique_ptr<unix_provider> create(std::shared_ptr<async::event_loop>);
    explicit unix_provider(std::unique_ptr<async::pipe>);

    void server(std::string endpoint) override;
    void client(std::string endpoint) override;

    void on_callback(std::function<void(std::unique_ptr<connection>)>) override;
    void on_error(std::function<void(std::string)>) override;

private:
    void set_error_handler();

private:
    std::unique_ptr<async::pipe> pipe_;
    std::function<void(std::unique_ptr<connection>)> callback_;
    std::function<void(std::string)> error_handler_;
};


} /* namespace myapp::rcon */
