#include "XmlProlog.h"

#include "XmlAttribute.h"

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

}

XmlPrologPtr 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());
    }
}
