/**
 * Swagger Petstore
 * This is a sample server Petstore server.  You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).  For this sample, you can use the api key `special-key` to test the authorization filters.
 *
 * OpenAPI spec version: 1.0.0
 * Contact: apiteam@swagger.io
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 */


#include "SWGPet.h"

#include "SWGHelpers.h"

#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>

namespace Swagger {

SWGPet::SWGPet(QString json) {
    init();
    this->fromJson(json);
}

SWGPet::SWGPet() {
    init();
}

SWGPet::~SWGPet() {
    this->cleanup();
}

void
SWGPet::init() {
    id = 0L;
    m_id_isSet = false;
    category = new SWGCategory();
    m_category_isSet = false;
    name = new QString("");
    m_name_isSet = false;
    photo_urls = new QList<QString*>();
    m_photo_urls_isSet = false;
    tags = new QList<SWGTag*>();
    m_tags_isSet = false;
    status = new QString("");
    m_status_isSet = false;
}

void
SWGPet::cleanup() {

    if(category != nullptr) { 
        delete category;
    }
    if(name != nullptr) { 
        delete name;
    }
    if(photo_urls != nullptr) { 
        auto arr = photo_urls;
        for(auto o: *arr) { 
            delete o;
        }
        delete photo_urls;
    }
    if(tags != nullptr) { 
        auto arr = tags;
        for(auto o: *arr) { 
            delete o;
        }
        delete tags;
    }
    if(status != nullptr) { 
        delete status;
    }
}

SWGPet*
SWGPet::fromJson(QString json) {
    QByteArray array (json.toStdString().c_str());
    QJsonDocument doc = QJsonDocument::fromJson(array);
    QJsonObject jsonObject = doc.object();
    this->fromJsonObject(jsonObject);
    return this;
}

void
SWGPet::fromJsonObject(QJsonObject pJson) {
    ::Swagger::setValue(&id, pJson["id"], "qint64", "");
    
    ::Swagger::setValue(&category, pJson["category"], "SWGCategory", "SWGCategory");
    
    ::Swagger::setValue(&name, pJson["name"], "QString", "QString");
    
    
    ::Swagger::setValue(&photo_urls, pJson["photoUrls"], "QList", "QString");
    
    ::Swagger::setValue(&tags, pJson["tags"], "QList", "SWGTag");
    ::Swagger::setValue(&status, pJson["status"], "QString", "QString");
    
}

QString
SWGPet::asJson ()
{
    QJsonObject obj = this->asJsonObject();
    QJsonDocument doc(obj);
    QByteArray bytes = doc.toJson();
    return QString(bytes);
}

QJsonObject
SWGPet::asJsonObject() {
    QJsonObject obj;
    if(m_id_isSet){
        obj.insert("id", QJsonValue(id));
    }
    if((category != nullptr) && (category->isSet())){
        toJsonValue(QString("category"), category, obj, QString("SWGCategory"));
    }
    if(name != nullptr && *name != QString("")){
        toJsonValue(QString("name"), name, obj, QString("QString"));
    }
    if(photo_urls->size() > 0){
        toJsonArray((QList<void*>*)photo_urls, obj, "photoUrls", "QString");
    }
    if(tags->size() > 0){
        toJsonArray((QList<void*>*)tags, obj, "tags", "SWGTag");
    }
    if(status != nullptr && *status != QString("")){
        toJsonValue(QString("status"), status, obj, QString("QString"));
    }

    return obj;
}

qint64
SWGPet::getId() {
    return id;
}
void
SWGPet::setId(qint64 id) {
    this->id = id;
    this->m_id_isSet = true;
}

SWGCategory*
SWGPet::getCategory() {
    return category;
}
void
SWGPet::setCategory(SWGCategory* category) {
    this->category = category;
    this->m_category_isSet = true;
}

QString*
SWGPet::getName() {
    return name;
}
void
SWGPet::setName(QString* name) {
    this->name = name;
    this->m_name_isSet = true;
}

QList<QString*>*
SWGPet::getPhotoUrls() {
    return photo_urls;
}
void
SWGPet::setPhotoUrls(QList<QString*>* photo_urls) {
    this->photo_urls = photo_urls;
    this->m_photo_urls_isSet = true;
}

QList<SWGTag*>*
SWGPet::getTags() {
    return tags;
}
void
SWGPet::setTags(QList<SWGTag*>* tags) {
    this->tags = tags;
    this->m_tags_isSet = true;
}

QString*
SWGPet::getStatus() {
    return status;
}
void
SWGPet::setStatus(QString* status) {
    this->status = status;
    this->m_status_isSet = true;
}


bool
SWGPet::isSet(){
    bool isObjectUpdated = false;
    do{
        if(m_id_isSet){ isObjectUpdated = true; break;}
        if(category != nullptr && category->isSet()){ isObjectUpdated = true; break;}
        if(name != nullptr && *name != QString("")){ isObjectUpdated = true; break;}
        if(photo_urls->size() > 0){ isObjectUpdated = true; break;}
        if(tags->size() > 0){ isObjectUpdated = true; break;}
        if(status != nullptr && *status != QString("")){ isObjectUpdated = true; break;}
    }while(false);
    return isObjectUpdated;
}
}

