#pragma once

#include "Socket.h"

#include <winsock2.h>

#include <functional>

class WinsockSocket : public Socket
{
public: 
    WinsockSocket(const std::string& address, unsigned port);

    WinsockSocket(SOCKET handle);

    ~WinsockSocket();

    std::string recieve() override;

    void respond(const std::string& message) override;

    std::string send(const std::string& message) override;

    using onIncomingConnectionFunc = std::function<void(SOCKET)>;
    void doListen(onIncomingConnectionFunc connectionFunc);

private:
    void initialize() override;
    void initializeForBind() override;

    void doConnect() override;

    void doBind() override;

    void onSockerError(const std::string& message);

    SOCKET mHandle{ INVALID_SOCKET };

    addrinfo* mAddressInfo{ nullptr };
};
