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




namespace WHISPER {

        StringData::StringData(std::string receivedMessage){
             msg = messages::header::Message();
        try {
            msg.ParseFromString(receivedMessage);
            topic_ = msg.topic();
            msgType_ = msg.msgtype();
            message_ = messages::stringData::StringData();
            senderUUID_ = msg.senderuuid();

            
                if (msg.mutable_payload()->Is<messages::stringData::StringData>()) 
                {
                    msg.mutable_payload()->UnpackTo(&message_);
                }
            
            data_ = message_.data();



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

        }


        WHISPER::StringData::StringData(std::string senderID, std::string data):
        Message(senderID,WHISPER::MsgTopics::DATA,WHISPER::STRINGDATA),data_(data)
        {
            message_ = messages::stringData::StringData();
           message_.set_data(data);

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


        }




}