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

#define StringDelimiter ';'

namespace SimCore {

 Identifier::Identifier() 
 {}   

Identifier::Identifier(std::uint32_t parent,std::uint32_t number, bool external):parent_(parent),number_(number),external_(external)
{

}


Identifier::Identifier(std::string str)
{
 std::vector<std::string> var =   UtilFunctions::explode(str,StringDelimiter);
 if (UtilFunctions::isNumber(var[0])) {
   parent_ = stoi(var[0]);
 }
 if (UtilFunctions::isNumber(var[1])) {
   number_ = stoi(var[1]);
 }
 if (UtilFunctions::isNumber(var[2])) {
   external_ = (bool)stoi(var[2]);

 }
}

std::string Identifier::serialize()
{
return std::to_string(parent_) + StringDelimiter + std::to_string(number_) + StringDelimiter + std::to_string(external_);

}


std::uint32_t Identifier::getNumber() const
{
    return number_;
}

std::uint32_t Identifier::getParentNumber() const
{
    return parent_;
}

bool Identifier::isValid()
{
    if (number_ > 0) {
        return true;
    }else 
    {
    return false;
    }

}

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



 bool operator==(const Identifier &lhs,const Identifier &rhs){
    if (lhs.number_ == rhs.number_ && lhs.external_ == rhs.external_ && lhs.parent_ == rhs.parent_) {
        return true;
    }else{
        return false;
    }
}


}