/**
 * OpenAPI Generated Petstore Client
 *
 * This is a sample of Petstore application.
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

#include "category.h"
#include "qoaihelpers.h"

using namespace Qt::StringLiterals;
using namespace QtOpenApiCommon;

namespace QtOpenAPI {
Category::Category(const QString &json)
{
    this->initializeModel();
    this->fromJson(json);
}

Category::Category()
{
    this->initializeModel();
}

Category::~Category()
{
}

void Category::initializeModel()
{
    m_id = {};
    m_idIsSet = false;
    // If value isn't set AND isn't required
    // it's counted as valid
    m_idIsValid = !false;

    m_name = {};
    m_nameIsSet = false;
    // If value isn't set AND isn't required
    // it's counted as valid
    m_nameIsValid = !false;
}

void Category::fromJson(const QString &jsonString)
{
    this->fromJsonValue(QJsonValue::fromJson(jsonString.toUtf8()));
}

void Category::fromJsonValue(const QJsonValue &json)
{
    Q_UNUSED(json);
    if (!json.isObject() || json.toObject().isEmpty()) {
        initializeModel();
        return;
    }
    const QJsonObject jsonObject = json.toObject();
    {
        const bool result = ::QtOpenApiCommon::fromJsonValue(m_id, jsonObject[u"id"_s]);
        if (result) {
            m_idIsValid = m_idIsSet = result;
        } else {
            m_idIsValid = !false;
            m_idIsSet = result;
        }
    }
    {
        const bool result = ::QtOpenApiCommon::fromJsonValue(m_name, jsonObject[u"name"_s]);
        if (result) {
            m_nameIsValid = m_nameIsSet = result;
        } else {
            m_nameIsValid = !false;
            m_nameIsSet = result;
        }
    }
}

QString Category::asJson() const
{
    return QString::fromUtf8(this->asJsonValue().toJson(QJsonDocument::Compact));
}

QJsonValue Category::asJsonValue() const
{
    QJsonObject obj;
    if (m_idIsSet) {
        obj.insert(u"id"_s, ::QtOpenApiCommon::toJsonValue(m_id));
    }
    if (m_nameIsSet) {
        obj.insert(u"name"_s, ::QtOpenApiCommon::toJsonValue(m_name));
    }
    return obj;
}

qint64 Category::getId() const
{
    return m_id;
}

void Category::setId(const qint64 &id)
{
    m_id = id;
    m_idIsValid = true;
    m_idIsSet = true;
}

bool Category::isIdValueSet() const
{
    return m_idIsSet;
}

bool Category::isIdValueValid() const
{
    return m_idIsValid;
}

QString Category::getName() const
{
    return m_name;
}

void Category::setName(const QString &name)
{
    m_name = name;
    m_nameIsValid = true;
    m_nameIsSet = true;
}

bool Category::isNameValueSet() const
{
    return m_nameIsSet;
}

bool Category::isNameValueValid() const
{
    return m_nameIsValid;
}

bool Category::isSet() const
{
    bool isObjectUpdated = false;
    do {
        if (m_idIsSet) {
            isObjectUpdated = true;
            break;
        }
        if (m_nameIsSet) {
            isObjectUpdated = true;
            break;
        }
    } while (false);
    return isObjectUpdated;
}

bool Category::isValid() const
{
    // only required properties are required for the object to be considered valid
    return true;
}

} // namespace QtOpenAPI
