#include "XmlProlog.h"


XmlProlog::XmlProlog(const std::string& tagName)
    : XmlElement(tagName),
      mVersion(XmlProlog::Version::V1_0),
      mEncoding(XmlProlog::Encoding::UTF8)
{

}

XmlPrologUPtr XmlProlog::Create(const std::string& tagName)
{
    return std::make_unique<XmlProlog>(tagName);
}

XmlProlog::Encoding XmlProlog::GetEncoding() const
{
    return mEncoding;
}

XmlProlog::Version XmlProlog::GetVersion() const
{
    return mVersion;
}

void XmlProlog::SetEncoding(const std::string& encoding)
{
    if(encoding == "UTF-8")
    {
        mEncoding = XmlProlog::Encoding::UTF8;
    }
}

void XmlProlog::SetVersion(const std::string& version)
{
    if(version == "1.0")
    {
        mVersion = XmlProlog::Version::V1_0;
    }
}

void XmlProlog::Update()
{
    if(const auto version = GetAttribute("version"))
    {
        SetVersion(version->GetValue());
    }

    if(const auto encoding = GetAttribute("encoding"))
    {
        SetEncoding(encoding->GetValue());
    }
}
