#ifndef BIBUNM_SENDER_H
#define BIBUNM_SENDER_H

#include "zmq_bazooka/sockets.h"
#include "bibun_messenging/payload_request.h"
#include "bibun_messenging/message.h"

namespace bibunm
{

class Sender
{
public:
   Sender() = delete;

   // Note: a sender should always destruct before the socket it uses.
   Sender(bzook::Socket *socket);

   Sender(const Sender &) = default;
   Sender(Sender &&other);

   void send(const Message &message, const std::string *destination = nullptr);
   void send(const internal_objects::PayloadRequest &request, const std::string *destination = nullptr);
   void send(const internal_objects::Request &request, const std::string *destination = nullptr);

   virtual ~Sender();
private:

   void send_push_routes(const std::list<std::string> &routes);

   ///
   /// \brief Send the associated request's commmand name.
   /// \param request The associated request.
   ///
   void send_command(const internal_objects::Request &request);

   ///
   /// \brief Send the associated request's headers on the socket.
   /// \param request The associated request.
   ///
   void send_protocol_headers(const internal_objects::Request &request);

   ///
   /// \brief Send the required parts of a request in the correct order.
   /// \param request The associated request.
   ///
   inline void send_common(const internal_objects::Request &request)
   {
      send_command(request);
      send_protocol_headers(request);
   }

   bzook::Socket *_socket;
};

}

#endif // BIBUNM_SENDER_H
