#pragma once
#include "eventloop.h"
#include <functional>
#include <memory>
#include <string>

namespace myapp::async {

class pipe
{
public:
    virtual ~pipe() = default;
    static std::unique_ptr<pipe> create(std::shared_ptr<event_loop>);

    virtual std::unique_ptr<pipe> accept() = 0;
    virtual void bind(std::string name) = 0;
    virtual void connect(std::string name, std::function<void()> callback) = 0;
    virtual void listen(int backlog, std::function<void()> callback) = 0;
    virtual void open(int fd) = 0;
    virtual void close() = 0;

    virtual void shutdown(std::function<void()>) = 0;
    virtual void write(std::string, std::function<void()>) = 0;
    virtual void read(std::function<void(std::string)> data, std::function<void()> end) = 0;
    virtual void stop_read() = 0;

    virtual void on_error(std::function<void( std::function<void()> )>) = 0;
};

} /* namespace myapp::async */
