#include "WHISPER/Messages/Message.hpp"
#include "WHISPER/Messages/Protos/pong.pb.h"
#include <WHISPER/Messages/Pong.hpp>
#include <memory>




namespace WHISPER {

        Pong::Pong(std::string receivedMessage){
             msg = messages::header::Message();
        try {
            msg.ParseFromString(receivedMessage);
            topic_ = msg.topic();
            sourceType_ = msg.sourcetype();
            msgType_ = msg.msgtype();
            message_ = messages::pong::Pong();
            deviceId_ = msg.sourceid();
            parentId_ = msg.parentid();

                if (msg.mutable_payload()->Is<messages::pong::Pong>()) 
                {
                    msg.mutable_payload()->UnpackTo(&message_);
                }
    
            port_ = message_.port();



        } catch (const std::exception& e) {
            LOG_S(ERROR)<<e.what();
        }

        }


        WHISPER::Pong::Pong(std::uint32_t parentID,std::uint32_t deviceID, SourceType src,std::uint32_t port):
        Message(parentID,deviceID,WHISPER::MsgTopics::MANAGEMENT,WHISPER::PONG,src),port_(port)
        {
            // message_ = messages::pong::Pong();
            if (message_.IsInitialized()) {
                message_.set_port(port_);            
            }

            auto payloadMessage = std::make_shared<google::protobuf::Any>();
            payloadMessage->PackFrom(message_);
            addPayLoad(payloadMessage);


        }




}