#pragma once
#include <netinet/in.h>
#include <string>
#include <set>
#include "Channel.hpp"

class Channel;
class Server;

class Client {
private:
    Server& _server;
    unsigned int _addrsize;
    struct sockaddr _addr;
    int _fd;
    std::string _buffer;
    bool _pass;
    bool _registered;
    bool _deleted;
    bool _welcomed;

    std::set<std::string> _channelsInvitedTo;
public:
    std::string nick;
    std::string username;
    std::string realname;

    Client(Server& _server);
    ~Client();

    int init(int servfd);
    int getFd() const;
    int recv();
    bool queuedMsg() const;
    std::string pollMsg();

    int sendCode(const std::string& code, const std::string& msg);
    int sendCode(const std::string& code, const std::string& msg0, const std::string& msg1);
    void fatalSendCode(const std::string& code, const std::string& msg);
    int sendMsg(std::string const& sender, std::string const& cmd,
            std::string const& trailing);
    int sendRaw(std::string const& msg);

    bool getPass() const;
    void setPass();

    bool getRegistered() const;
    void setRegistered();

    bool getWelcomed() const;
    void setWelcomed();

    void addInvite(Channel const& channel);
    bool isInvited(Channel const& channel);

    bool operator==(Client const& rhs) const;
    bool operator==(std::string const& nick) const;
};
