/**
 * Qt6 Common library
 *
 * Copyright (C) 2026 The Qt Company Ltd.
 * SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

#include "qoaiobject.h"

#include <QtCore/qjsonobject.h>

QT_BEGIN_NAMESPACE

namespace QtOpenApiCommon {

class QOAIObjectPrivate
{
public:
    QJsonObject m_jsonObj;
};

QOAIObject::QOAIObject()
    : d(new QOAIObjectPrivate)
{
}

QOAIObject::QOAIObject(const QString &json)
    : d(new QOAIObjectPrivate)
{
    fromJson(json);
}

QOAIObject::QOAIObject(const QOAIObject &other)
    : d(std::make_unique<QOAIObjectPrivate>(*other.d))
{
}

QOAIObject &QOAIObject::operator=(const QOAIObject &other)
{
    if(this != &other)
        d = std::make_unique<QOAIObjectPrivate>(*other.d);
    return *this;
}

QOAIObject::QOAIObject(QOAIObject &&) noexcept = default;
QOAIObject &QOAIObject::operator=(QOAIObject &&) noexcept = default;
QOAIObject::~QOAIObject() = default;

QJsonValue QOAIObject::asJsonValue() const
{
    return QJsonValue(d->m_jsonObj);
}

QString QOAIObject::asJson() const
{
    const QJsonDocument doc(d->m_jsonObj);
    const QByteArray bytes = doc.toJson(QJsonDocument::Compact);
    return QString::fromUtf8(bytes);
}

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

void QOAIObject::fromJsonValue(const QJsonValue &json)
{
    if (json.isObject())
        d->m_jsonObj = json.toObject();
    else
        d->m_jsonObj = {};
}

bool QOAIObject::isSet() const
{
    return !d->m_jsonObj.empty();
}

bool QOAIObject::isValid() const
{
    return true;
}

} // namespace QtOpenApiCommon

QT_END_NAMESPACE
