/**
 * 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 "SWGAmount.h"

#include "SWGHelpers.h"

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

namespace Swagger {

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

SWGAmount::SWGAmount() {
    init();
}

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

void
SWGAmount::init() {
    value = 0.0;
    m_value_isSet = false;
    currency = new SWGCurrency();
    m_currency_isSet = false;
}

void
SWGAmount::cleanup() {

    if(currency != nullptr) { 
        delete currency;
    }
}

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

void
SWGAmount::fromJsonObject(QJsonObject pJson) {
    ::Swagger::setValue(&value, pJson["value"], "double", "");
    
    ::Swagger::setValue(&currency, pJson["currency"], "SWGCurrency", "SWGCurrency");
    
}

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

QJsonObject
SWGAmount::asJsonObject() {
    QJsonObject obj;
    if(m_value_isSet){
        obj.insert("value", QJsonValue(value));
    }
    if((currency != nullptr) && (currency->isSet())){
        toJsonValue(QString("currency"), currency, obj, QString("SWGCurrency"));
    }

    return obj;
}

double
SWGAmount::getValue() {
    return value;
}
void
SWGAmount::setValue(double value) {
    this->value = value;
    this->m_value_isSet = true;
}

SWGCurrency*
SWGAmount::getCurrency() {
    return currency;
}
void
SWGAmount::setCurrency(SWGCurrency* currency) {
    this->currency = currency;
    this->m_currency_isSet = true;
}


bool
SWGAmount::isSet(){
    bool isObjectUpdated = false;
    do{
        if(m_value_isSet){ isObjectUpdated = true; break;}
        if(currency != nullptr && currency->isSet()){ isObjectUpdated = true; break;}
    }while(false);
    return isObjectUpdated;
}
}

