#include "SimCore/SimCore.hpp"
#include <SimCore/Identifier.hpp>
#include <iterator>
#include <random>
#include <string>
#include <utility>
#include <vector>

#include <crossguid/guid.hpp>

#define StringDelimiter ';'

namespace SimCore {

 Identifier::Identifier(bool external):uuid_(xg::newGuid().str()),external_(external)
 {}   


Identifier::Identifier(xg::Guid uuid,bool external ):uuid_(uuid.str()),external_(external)
{

}

SimCore::Identifier::Identifier(messages::track::Identifier id)
{
    this->uuid_ = id.uuid();
    this->external_ = id.external();

}

Identifier::Identifier(std::string str)
{
 std::vector<std::string> var =   UtilFunctions::explode(str,StringDelimiter);

 if (var[0] != "") {
    uuid_ = var[0];
 }
 if (UtilFunctions::isNumber(var[1])) {
   external_ = (bool)stoi(var[1]);
 }
}

std::string Identifier::serialize() const 
{
return  uuid_+ StringDelimiter + std::to_string(external_);
}




bool Identifier::isValid()
{
    if (std::empty(this->uuid_) ) {
        return true;
    }else 
    {
        return false;
    }

}

bool Identifier::isExternal() const
{
    if (external_ == true) {
        return true;
    }else {
        return false;
    }
}

std::string Identifier::getUUID() const
{
    return uuid_;
}




 bool operator==(const Identifier &lhs,const Identifier &rhs){
    if (lhs.uuid_ == rhs.uuid_ && lhs.external_ == rhs.external_) {
        return true;
    }

    return false;
}


}