#include "SimCore/Messages/SimTrack.hpp"
#include "nlohmann/json.hpp"
#include <SimControl/TrackItem.hpp>



namespace SimControl 
{

    TrackItem::TrackItem(SimCore::SimTrack track)
    :SimCore::SimTrack(track), markedAsDeleted(false),lastReceiveTimestamp_(time(0))
    {
    }



     void TrackItem::markAsDelete()
     {
        markedAsDeleted = true;
     }

     bool TrackItem::isMarkedAsDelete()
     {
        return markedAsDeleted;
     }

    std::time_t TrackItem::getLastUpdateTimestamp()
    {
        return lastReceiveTimestamp_;
    }

    nlohmann::json TrackItem::toJSON()
    {

        nlohmann::json j;
        j["id"] = this->getIdentifier().getUUID();
        j["Name"] = this->Name.getValue();
        j["Course"] = this->Course.getValue();
        j["Speed"] = this->Speed.getValue();
        j["External"] = this->getIdentifier().isExternal();
        j["Position"] = {this->getPosition().getGeodesicPos()[SimCore::LATITUDE], this->getPosition().getGeodesicPos()[SimCore::LONGITUDE]};
        j["Height"] = this->getPosition().getGeodesicPos()[SimCore::HEIGHT];
        j["Type"] = SimCore::Kind::EntityKindMap[this->EntityKind.getValue()];
        j["Side"] = SimCore::Side::EntitySideMap[this->EntitySide.getValue()];
        return j;
    }
    std::string TrackItem::toString()
    {
        return toJSON().dump();
    }



}