/**
 * 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 "pet.h"
#include "qoaihelpers.h"

using namespace Qt::StringLiterals;
using namespace QtOpenApiCommon;

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

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

Pet::~Pet()
{
}

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

    m_category = {};
    m_categoryIsSet = false;
    m_categoryIsValid = m_category.isValid();

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

    m_photoUrls = {};
    m_photoUrlsIsSet = false;
    // If value isn't set AND isn't required
    // it's counted as valid
    m_photoUrlsIsValid = !true;

    m_tags = {};
    m_tagsIsSet = false;
    m_tagsIsValid = !false;

    m_status = {};
    m_statusIsSet = false;
    m_statusIsValid = m_status.isValid();

    m_age = {};
    m_ageIsSet = false;
    // If value isn't set AND isn't required
    // it's counted as valid
    m_ageIsValid = !false;

    m_patience = {};
    m_patienceIsSet = false;
    // If value isn't set AND isn't required
    // it's counted as valid
    m_patienceIsValid = !false;
}

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

void Pet::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 QJsonValue modelValue = jsonObject[u"category"_s];
        if (modelValue.isObject()) {
            ::QtOpenApiCommon::fromJsonValue(m_category, modelValue);
            m_categoryIsValid = m_category.isValid();
            // NOTE: An empty JSON object is still a valid value
            // for models without required properties.
            // Users may intentionally set it for specific reasons.
            m_categoryIsSet = m_category.isSet() || (m_categoryIsValid && modelValue.toObject().isEmpty());
        } else {
            m_category = {};
            m_categoryIsValid = m_category.isValid();
            m_categoryIsSet = false;
        }
    }
    {
        const bool result = ::QtOpenApiCommon::fromJsonValue(m_name, jsonObject[u"name"_s]);
        if (result) {
            m_nameIsValid = m_nameIsSet = result;
        } else {
            m_nameIsValid = !true;
            m_nameIsSet = result;
        }
    }
    {
        const bool result = ::QtOpenApiCommon::fromJsonValue(m_photoUrls, jsonObject[u"photoUrls"_s]);
        if (result) {
            m_photoUrlsIsValid = m_photoUrlsIsSet = result;
        } else {
            m_photoUrlsIsValid = !true;
            m_photoUrlsIsSet = result;
        }
    }
    if (jsonObject[u"tags"_s].isArray() || jsonObject[u"tags"_s].isObject()) {
        m_tagsIsValid = ::QtOpenApiCommon::fromJsonValue(m_tags, jsonObject[u"tags"_s]);
        m_tagsIsSet = !jsonObject[u"tags"_s].isNull() && m_tagsIsValid;
    }
    else { // fallback for wrong data type
        m_tags.clear();
        m_tagsIsValid = !false;
        m_tagsIsSet = false;
    }
    {
        const bool result = ::QtOpenApiCommon::fromJsonValue(m_status, jsonObject[u"status"_s]);
        if (result) {
            m_statusIsValid = m_statusIsSet = m_status.isSet();
        } else {
            m_statusIsValid = !false;
            m_statusIsSet = result;
        }
    }
    {
        const bool result = ::QtOpenApiCommon::fromJsonValue(m_age, jsonObject[u"age"_s]);
        if (result) {
            m_ageIsValid = m_ageIsSet = result;
        } else {
            m_ageIsValid = !false;
            m_ageIsSet = result;
        }
    }
    {
        const bool result = ::QtOpenApiCommon::fromJsonValue(m_patience, jsonObject[u"patience"_s]);
        if (result) {
            m_patienceIsValid = m_patienceIsSet = result;
        } else {
            m_patienceIsValid = !false;
            m_patienceIsSet = result;
        }
    }
}

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

QJsonValue Pet::asJsonValue() const
{
    QJsonObject obj;
    if (m_idIsSet) {
        obj.insert(u"id"_s, ::QtOpenApiCommon::toJsonValue(m_id));
    }
    if (m_categoryIsSet) {
        obj.insert(u"category"_s, ::QtOpenApiCommon::toJsonValue(m_category));
    }
    if (m_nameIsSet) {
        obj.insert(u"name"_s, ::QtOpenApiCommon::toJsonValue(m_name));
    }
    if (m_photoUrlsIsSet) {
        obj.insert(u"photoUrls"_s, ::QtOpenApiCommon::toJsonValue(m_photoUrls));
    }
    if (m_tagsIsSet) {
        obj.insert(u"tags"_s, ::QtOpenApiCommon::toJsonValue(m_tags));
    }
    if (m_statusIsSet) {
        obj.insert(u"status"_s, ::QtOpenApiCommon::toJsonValue(m_status));
    }
    if (m_ageIsSet) {
        obj.insert(u"age"_s, ::QtOpenApiCommon::toJsonValue(m_age));
    }
    if (m_patienceIsSet) {
        obj.insert(u"patience"_s, ::QtOpenApiCommon::toJsonValue(m_patience));
    }
    return obj;
}

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

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

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

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

Category Pet::getCategory() const
{
    return m_category;
}

void Pet::setCategory(const Category &category)
{
    m_category = category;
    m_categoryIsValid = true && category.isValid();
    // NOTE: An empty JSON object is still a valid value
    // for models without required properties.
    // Users may intentionally set it for specific reasons.
    m_categoryIsSet = m_category.isSet() || (m_categoryIsValid && category.asJsonValue().toObject().isEmpty());
}

bool Pet::isCategoryValueSet() const
{
    return m_categoryIsSet;
}

bool Pet::isCategoryValueValid() const
{
    return m_categoryIsValid;
}

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

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

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

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

QList<QString> Pet::getPhotoUrls() const
{
    return m_photoUrls;
}

void Pet::setPhotoUrls(const QList<QString> &photoUrls)
{
    m_photoUrls = photoUrls;
    m_photoUrlsIsValid = true;
    m_photoUrlsIsSet = true;
}

bool Pet::isPhotoUrlsValueSet() const
{
    return m_photoUrlsIsSet;
}

bool Pet::isPhotoUrlsValueValid() const
{
    return m_photoUrlsIsValid;
}

QList<Tag> Pet::getTags() const
{
    return m_tags;
}

void Pet::setTags(const QList<Tag> &tags)
{
    m_tags = tags;
    m_tagsIsValid = true;
    m_tagsIsSet = m_tagsIsValid;
}

bool Pet::isTagsValueSet() const
{
    return m_tagsIsSet;
}

bool Pet::isTagsValueValid() const
{
    return m_tagsIsValid;
}

PetStatus Pet::getStatus() const
{
    return m_status;
}

void Pet::setStatus(const PetStatus &status)
{
    m_status = status;
    m_statusIsValid = true && status.isValid();
    m_statusIsSet = m_status.isSet();
}

bool Pet::isStatusValueSet() const
{
    return m_statusIsSet;
}

bool Pet::isStatusValueValid() const
{
    return m_statusIsValid;
}

qint32 Pet::getAge() const
{
    return m_age;
}

void Pet::setAge(const qint32 &age)
{
    m_age = age;
    m_ageIsValid = true;
    m_ageIsSet = true;
}

bool Pet::isAgeValueSet() const
{
    return m_ageIsSet;
}

bool Pet::isAgeValueValid() const
{
    return m_ageIsValid;
}

qint32 Pet::getPatience() const
{
    return m_patience;
}

void Pet::setPatience(const qint32 &patience)
{
    m_patience = patience;
    m_patienceIsValid = true;
    m_patienceIsSet = true;
}

bool Pet::isPatienceValueSet() const
{
    return m_patienceIsSet;
}

bool Pet::isPatienceValueValid() const
{
    return m_patienceIsValid;
}

bool Pet::isSet() const
{
    bool isObjectUpdated = false;
    do {
        if (m_idIsSet) {
            isObjectUpdated = true;
            break;
        }
        if (m_categoryIsSet) {
            isObjectUpdated = true;
            break;
        }
        if (m_nameIsSet) {
            isObjectUpdated = true;
            break;
        }
        if (m_photoUrlsIsSet) {
            isObjectUpdated = true;
            break;
        }
        if (m_tagsIsSet) {
            isObjectUpdated = true;
            break;
        }
        if (m_statusIsSet) {
            isObjectUpdated = true;
            break;
        }
        if (m_ageIsSet) {
            isObjectUpdated = true;
            break;
        }
        if (m_patienceIsSet) {
            isObjectUpdated = true;
            break;
        }
    } while (false);
    return isObjectUpdated;
}

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

} // namespace QtOpenAPI
