#pragma once

#include "abstract_coder.hpp"
#include "coroutine.hpp"
#include "fd_event.hpp"
#include "reactor.hpp"
#include "tcp_buffer.hpp"

namespace tinyrpc { 
    class TcpServer;
    class TcpConnection {
    public:
        enum class State{
            Disconnected,
            Connected
        };

        
    public:
        TcpConnection(int fd, Reactor& reactor, TcpServer& ser);
        void clearClient();
        void mainLoopFun();

        ~TcpConnection();
        
    private:
        void input();
        void output();
        void process();

        
    private:
        FdEvent *m_fdEvent;
        Coroutine m_mainCoroutine;
        State m_state{State::Connected};
        TcpBuffer m_writeBuffer{};
        TcpBuffer m_readBuffer{};
        Reactor& m_reactor;
        TcpServer& m_server; 
    };

}