/**
 * 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 "petapi.h"
#include "qoaiserverconfiguration.h"

#include <QtCore/qanystringview.h>
#include <QtCore/qflags.h>
#include <QtCore/qjsonarray.h>
#include <QtCore/qjsondocument.h>
#include <QtNetwork/qhttpmultipart.h>
#include <QtNetwork/qnetworkaccessmanager.h>
#include <QtNetwork/qnetworkreply.h>
#include <QtNetwork/qnetworkrequestfactory.h>
#include <QtNetwork/qrestaccessmanager.h>

#include <string_view>

using namespace Qt::StringLiterals;
using namespace std::string_view_literals;

using namespace QtOpenApiCommon;

namespace QtOpenAPI {

PetApi::PetApi(QObject *parent)
    : QOAIBaseApi(parent)
{
    initializeServerConfigs();
}

PetApi::~PetApi()
{
}

void PetApi::initializeServerConfigs()
{
    //Default server
    QList<QOAIServerConfiguration> defaultConf = QList<QOAIServerConfiguration>();
    //varying endpoint server
    defaultConf.append(QOAIServerConfiguration(
        u"http://127.0.0.1:19080/v2"_s,
        u"No description provided"_s,
        QMap<QString, QOAIServerVariable>()));
    {
        setServersForOperation(u"addPet"_s, defaultConf);
    }
    {
        setServersForOperation(u"deletePet"_s, defaultConf);
    }
    {
        setServersForOperation(u"findPetsByAgeAndPatience"_s, defaultConf);
    }
    {
        setServersForOperation(u"findPetsByStatus"_s, defaultConf);
    }
    {
        setServersForOperation(u"findPetsByTags"_s, defaultConf);
    }
    {
        setServersForOperation(u"findPetsImageById"_s, defaultConf);
    }
    {
        setServersForOperation(u"getJsonFile"_s, defaultConf);
    }
    {
        setServersForOperation(u"getPetById"_s, defaultConf);
    }
    {
        setServersForOperation(u"updatePet"_s, defaultConf);
    }
    {
        setServersForOperation(u"updatePetWithForm"_s, defaultConf);
    }
    {
        setServersForOperation(u"uploadFile"_s, defaultConf);
    }
}

/**
* \fn void PetApi::addPet(const Pet &pet)
* 'addPet' operation sends the request to a server.
* The request parameters are defined by a specification file.

* @param[in] pet Pet [required]
*/

/**
* \fn template < Functor, > void PetApi::addPet(const Pet &pet, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'addPet' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
*    addPet(pet, this, [&](const QRestReply &reply, const Pet &summary) { if (reply.isSuccess()) ... });
* \endcode

* @param[in] pet Pet [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/

/**
* \fn void PetApi::addPetCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by addPetFinished() or
* being returned as a callback parameter of addPet() request.
* @param[in] reply const QRestReply &
*/

/**
* \fn void PetApi::addPetWithDataImpl(const Pet &pet, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the addPet() operation request.

* @param[in] pet Pet [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void PetApi::addPetWithDataImpl(const Pet &pet, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
    QtPrivate::SlotObjUniquePtr slotPtr(slot);
    setBaseServerUrl(u"addPet"_s);
    QString fullPath = u"/pet"_s;
    if (const QString un = username(), p = password(); !un.isEmpty() && !p.isEmpty()) {
        QByteArray b64;
        b64.append(un.toUtf8() + ":" + p.toUtf8());
        setHeader(QHttpHeaders::WellKnownHeader::Authorization, "Basic "_L1 + b64.toBase64());
    }

    QOAIHttpRequestInput input(fullPath, "POST"_L1);
    input.headers().replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
    {
        const QByteArray output = pet.asJson().toUtf8();
        input.setRequestBody(output);
    }
    QByteArray requestContent;
    QNetworkRequest request
        = QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
                                                         networkRequestFactory(),
                                                         responseCompressionEnabled(),
                                                         requestCompressionEnabled());
    QNetworkReply *reply = execute(input, request, requestContent);
    if (reply != nullptr) {
        reply->setParent(this);
        setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
        connect(reply, &QNetworkReply::finished, this, [this, reply] {
            addPetCallback(QRestReply(reply));
        });
        connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
            if (reply) {
                emit addPetErrorOccurred(reply->error(), reply->errorString());
                QOAICallerInfo callerInfo = takeCallerInfo(reply);
                if (callerInfo.slot) {
                    Pet empty;
                    QRestReply restRepl(reply);
                    void *argv[] = { nullptr, &restRepl, &empty };
                    QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
                    callerInfo.slot->call(context, argv);
                }
            }
        });
    }
}

void PetApi::addPetCallback(const QRestReply &reply)
{
    auto netReply = reply.networkReply();
    if (netReply)
        netReply->disconnect(this);
    if (!reply.isSuccess())
        return;

    const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory());
    Pet output(response);
    // Check if callback is provided
    QOAICallerInfo callerInfo = takeCallerInfo(netReply);
    if (callerInfo.slot) {
        void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
        QObject *context = callerInfo.contextObject
                        ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
        callerInfo.slot->call(context, argv);
    }
    emit addPetFinished(output);
}

/**
* \fn void PetApi::deletePet(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &apiKey = QtOpenApiCommon::OptionalParameter<QString>())
* 'deletePet' operation sends the request to a server.
* The request parameters are defined by a specification file.

* @param[in] petId qint64 [required]
* @param[in] apiKey QString [optional]
*/

/**
* \fn template < Functor, > void PetApi::deletePet(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &apiKey = QtOpenApiCommon::OptionalParameter<QString>(), const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'deletePet' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
*    deletePet(petId, apiKey, this, [&](const QRestReply &reply) { if (reply.isSuccess()) ... });
* \endcode

* @param[in] petId qint64 [required]
* @param[in] apiKey QString [optional]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/

/**
* \fn void PetApi::deletePetCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by deletePetFinished() or
* being returned as a callback parameter of deletePet() request.
* @param[in] reply const QRestReply &
*/

/**
* \fn void PetApi::deletePetWithDataImpl(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &apiKey, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the deletePet() operation request.

* @param[in] petId qint64 [required]
* @param[in] apiKey QString [optional]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void PetApi::deletePetWithDataImpl(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &apiKey, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
    QtPrivate::SlotObjUniquePtr slotPtr(slot);
    setBaseServerUrl(u"deletePet"_s);
    QString fullPath = u"/pet/{petId}"_s;
    if (const auto token = bearerToken(); !token.isEmpty())
        setHeader(QHttpHeaders::WellKnownHeader::Authorization, "Bearer "_L1 + token);
    {
        QString petIdPathParam = u"{%1}"_s.arg(u"petId"_s);

        SerializationFlags flags;
        flags.setFlag(SerializationFlag::Object, false || false);
        flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
        flags.setFlag(SerializationFlag::Explode, false);

        SerializationOptions opts;
        opts.style = "simple"sv.empty() ? "simple" : "simple";
        opts.prefix = getParamStylePrefix(opts.style);
        opts.delimiter = getParamStyleDelimiter(opts.style, flags);
        opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
        opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"petId"_s), flags);
        opts.flags = flags;
        QString paramString = opts.prefix + opts.suffix;
        paramString += QUrl::toPercentEncoding(::QtOpenApiCommon::toStringValue(petId));
        // In case style=matrix and paramString is empty due to any reasons,
        // we serialize it like undefined value and delete '='.
        // Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
        if ((paramString == opts.prefix + opts.suffix) && opts.style == "matrix")
            paramString.chop(1);
        fullPath.replace(petIdPathParam, paramString);
    }

    QOAIHttpRequestInput input(fullPath, "DELETE"_L1);
    if (apiKey.hasValue())
    {

        SerializationFlags flags;
        flags.setFlag(SerializationFlag::Object, false || false);
        flags.setFlag(SerializationFlag::NeedPercentEncoding, false);
        flags.setFlag(SerializationFlag::Explode, false);

        SerializationOptions opts;
        opts.style = "simple"sv.empty() ? "simple" : "simple";
        opts.prefix = getParamStylePrefix(opts.style);
        opts.delimiter = getParamStyleDelimiter(opts.style, flags);
        opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
        opts.suffix = getParamStyleSuffix(opts.style, u"api_key"_s, flags);
        opts.flags = flags;

        const QString headerString = toStringValue(apiKey.value());
        if (!headerString.isEmpty())
            input.headers().replaceOrAppend(u"api_key"_s, headerString);
    }
    QByteArray requestContent;
    QNetworkRequest request
        = QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
                                                         networkRequestFactory(),
                                                         responseCompressionEnabled(),
                                                         requestCompressionEnabled());
    QNetworkReply *reply = execute(input, request, requestContent);
    if (reply != nullptr) {
        reply->setParent(this);
        setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
        connect(reply, &QNetworkReply::finished, this, [this, reply] {
            deletePetCallback(QRestReply(reply));
        });
        connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
            if (reply) {
                emit deletePetErrorOccurred(reply->error(), reply->errorString());
                QOAICallerInfo callerInfo = takeCallerInfo(reply);
                if (callerInfo.slot) {
                    QRestReply restRepl(reply);
                    void *argv[] = { nullptr, &restRepl };
                    QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
                    callerInfo.slot->call(context, argv);
                }
            }
        });
    }
}

void PetApi::deletePetCallback(const QRestReply &reply)
{
    auto netReply = reply.networkReply();
    if (netReply)
        netReply->disconnect(this);
    if (!reply.isSuccess())
        return;

    // Check if callback is provided
    QOAICallerInfo callerInfo = takeCallerInfo(netReply);
    if (callerInfo.slot) {
        void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
        QObject *context = callerInfo.contextObject
                        ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
        callerInfo.slot->call(context, argv);
    }
    emit deletePetFinished();
}

/**
* \fn void PetApi::findPetsByAgeAndPatience(const QList<qint32> &petData)
* 'findPetsByAgeAndPatience' operation sends the request to a server.
* The request parameters are defined by a specification file.

* @param[in] petData QList<qint32> [required]
*/

/**
* \fn template < Functor, > void PetApi::findPetsByAgeAndPatience(const QList<qint32> &petData, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'findPetsByAgeAndPatience' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
*    findPetsByAgeAndPatience(petData, this, [&](const QRestReply &reply, const QList<Pet> &summary) { if (reply.isSuccess()) ... });
* \endcode

* @param[in] petData QList<qint32> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/

/**
* \fn void PetApi::findPetsByAgeAndPatienceCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by findPetsByAgeAndPatienceFinished() or
* being returned as a callback parameter of findPetsByAgeAndPatience() request.
* @param[in] reply const QRestReply &
*/

/**
* \fn void PetApi::findPetsByAgeAndPatienceWithDataImpl(const QList<qint32> &petData, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the findPetsByAgeAndPatience() operation request.

* @param[in] petData QList<qint32> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void PetApi::findPetsByAgeAndPatienceWithDataImpl(const QList<qint32> &petData, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
    QtPrivate::SlotObjUniquePtr slotPtr(slot);
    setBaseServerUrl(u"findPetsByAgeAndPatience"_s);
    QString fullPath = u"/pet/findPetsByAgeAndPatience/{petData}"_s;
    {
        QString petDataPathParam = u"{%1}"_s.arg(u"petData"_s);

        SerializationFlags flags;
        flags.setFlag(SerializationFlag::Object, false || false);
        flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
        flags.setFlag(SerializationFlag::Explode, false);

        SerializationOptions opts;
        opts.style = "simple"sv.empty() ? "simple" : "simple";
        opts.prefix = getParamStylePrefix(opts.style);
        opts.delimiter = getParamStyleDelimiter(opts.style, flags);
        opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
        opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"petData"_s), flags);
        opts.flags = flags;
        QString paramString = opts.prefix + opts.suffix;
        paramString = opts.prefix + serializeArrayValue(petData, opts);
        // In case style=matrix and paramString is empty due to any reasons,
        // we serialize it like undefined value and delete '='.
        // Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
        if ((paramString == opts.prefix + opts.suffix) && opts.style == "matrix")
            paramString.chop(1);
        fullPath.replace(petDataPathParam, paramString);
    }

    QOAIHttpRequestInput input(fullPath, "GET"_L1);
    QByteArray requestContent;
    QNetworkRequest request
        = QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
                                                         networkRequestFactory(),
                                                         responseCompressionEnabled(),
                                                         requestCompressionEnabled());
    QNetworkReply *reply = execute(input, request, requestContent);
    if (reply != nullptr) {
        reply->setParent(this);
        setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
        connect(reply, &QNetworkReply::finished, this, [this, reply] {
            findPetsByAgeAndPatienceCallback(QRestReply(reply));
        });
        connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
            if (reply) {
                emit findPetsByAgeAndPatienceErrorOccurred(reply->error(), reply->errorString());
                QOAICallerInfo callerInfo = takeCallerInfo(reply);
                if (callerInfo.slot) {
                    QList<Pet> empty;
                    QRestReply restRepl(reply);
                    void *argv[] = { nullptr, &restRepl, &empty };
                    QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
                    callerInfo.slot->call(context, argv);
                }
            }
        });
    }
}

void PetApi::findPetsByAgeAndPatienceCallback(const QRestReply &reply)
{
    auto netReply = reply.networkReply();
    if (netReply)
        netReply->disconnect(this);
    if (!reply.isSuccess())
        return;

    const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory());
    QList<Pet> output;
    const QJsonDocument doc = QJsonDocument::fromJson(response);
    if (!doc.isNull() && doc.isArray()) {
        const QJsonArray jsonArray = doc.array();
        for (const QJsonValue &obj : jsonArray) {
            Pet val;
            const bool ok = ::QtOpenApiCommon::fromJsonValue(val, obj);
            if (!ok)
                qWarning("%s: Failed to convert QJsonValue to Pet.", Q_FUNC_INFO);
            output.append(val);
        }
    } else {
        qWarning("%s: Failed to parse the response as a JSON array.", Q_FUNC_INFO);
    }
    // Check if callback is provided
    QOAICallerInfo callerInfo = takeCallerInfo(netReply);
    if (callerInfo.slot) {
        void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
        QObject *context = callerInfo.contextObject
                        ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
        callerInfo.slot->call(context, argv);
    }
    emit findPetsByAgeAndPatienceFinished(output);
}

/**
* \fn void PetApi::findPetsByStatus(const QList<QString> &status)
* 'findPetsByStatus' operation sends the request to a server.
* The request parameters are defined by a specification file.

* @param[in] status QList<QString> [required]
*/

/**
* \fn template < Functor, > void PetApi::findPetsByStatus(const QList<QString> &status, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'findPetsByStatus' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
*    findPetsByStatus(status, this, [&](const QRestReply &reply, const QList<Pet> &summary) { if (reply.isSuccess()) ... });
* \endcode

* @param[in] status QList<QString> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/

/**
* \fn void PetApi::findPetsByStatusCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by findPetsByStatusFinished() or
* being returned as a callback parameter of findPetsByStatus() request.
* @param[in] reply const QRestReply &
*/

/**
* \fn void PetApi::findPetsByStatusWithDataImpl(const QList<QString> &status, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the findPetsByStatus() operation request.

* @param[in] status QList<QString> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void PetApi::findPetsByStatusWithDataImpl(const QList<QString> &status, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
    QtPrivate::SlotObjUniquePtr slotPtr(slot);
    setBaseServerUrl(u"findPetsByStatus"_s);
    QString fullPath = u"/pet/findByStatus"_s;
    int queryParamCounter = 0;
    {
        [[maybe_unused]] QString paramString;

        SerializationFlags flags;
        flags.setFlag(SerializationFlag::Object, false || false);
        flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
        flags.setFlag(SerializationFlag::Explode, false);

        SerializationOptions opts;
        opts.style = "form"sv.empty() ? "form" : "form";
        opts.prefix = getParamStylePrefix(opts.style);
        opts.delimiter = getParamStyleDelimiter(opts.style, flags);
        opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
        opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"status"_s), flags);
        opts.flags = flags;
        if ((fullPath.indexOf(u'?') != fullPath.size() - 1) && (queryParamCounter == 0))
            fullPath.append(opts.prefix);
        {
            if (queryParamCounter > 0)
                fullPath.append(u'&');
            fullPath.append(serializeArrayValue(status, opts));
            queryParamCounter++;
        }
    }
    QOAIHttpRequestInput input(fullPath, "GET"_L1);
    QByteArray requestContent;
    QNetworkRequest request
        = QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
                                                         networkRequestFactory(),
                                                         responseCompressionEnabled(),
                                                         requestCompressionEnabled());
    QNetworkReply *reply = execute(input, request, requestContent);
    if (reply != nullptr) {
        reply->setParent(this);
        setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
        connect(reply, &QNetworkReply::finished, this, [this, reply] {
            findPetsByStatusCallback(QRestReply(reply));
        });
        connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
            if (reply) {
                emit findPetsByStatusErrorOccurred(reply->error(), reply->errorString());
                QOAICallerInfo callerInfo = takeCallerInfo(reply);
                if (callerInfo.slot) {
                    QList<Pet> empty;
                    QRestReply restRepl(reply);
                    void *argv[] = { nullptr, &restRepl, &empty };
                    QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
                    callerInfo.slot->call(context, argv);
                }
            }
        });
    }
}

void PetApi::findPetsByStatusCallback(const QRestReply &reply)
{
    auto netReply = reply.networkReply();
    if (netReply)
        netReply->disconnect(this);
    if (!reply.isSuccess())
        return;

    const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory());
    QList<Pet> output;
    const QJsonDocument doc = QJsonDocument::fromJson(response);
    if (!doc.isNull() && doc.isArray()) {
        const QJsonArray jsonArray = doc.array();
        for (const QJsonValue &obj : jsonArray) {
            Pet val;
            const bool ok = ::QtOpenApiCommon::fromJsonValue(val, obj);
            if (!ok)
                qWarning("%s: Failed to convert QJsonValue to Pet.", Q_FUNC_INFO);
            output.append(val);
        }
    } else {
        qWarning("%s: Failed to parse the response as a JSON array.", Q_FUNC_INFO);
    }
    // Check if callback is provided
    QOAICallerInfo callerInfo = takeCallerInfo(netReply);
    if (callerInfo.slot) {
        void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
        QObject *context = callerInfo.contextObject
                        ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
        callerInfo.slot->call(context, argv);
    }
    emit findPetsByStatusFinished(output);
}

/**
* \fn void PetApi::findPetsByTags(const QList<QString> &tags)
* \deprecated 'findPetsByTags' operation sends the request to a server.
* The request parameters are defined by a specification file.

* @param[in] tags QList<QString> [required]
*/

/**
* \fn template < Functor, > void PetApi::findPetsByTags(const QList<QString> &tags, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* \deprecated 'findPetsByTags' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
*    findPetsByTags(tags, this, [&](const QRestReply &reply, const QList<Pet> &summary) { if (reply.isSuccess()) ... });
* \endcode

* @param[in] tags QList<QString> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/

/**
* \fn void PetApi::findPetsByTagsCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by findPetsByTagsFinished() or
* being returned as a callback parameter of findPetsByTags() request.
* @param[in] reply const QRestReply &
*/

/**
* \fn void PetApi::findPetsByTagsWithDataImpl(const QList<QString> &tags, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the findPetsByTags() operation request.

* @param[in] tags QList<QString> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void PetApi::findPetsByTagsWithDataImpl(const QList<QString> &tags, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
    QtPrivate::SlotObjUniquePtr slotPtr(slot);
    setBaseServerUrl(u"findPetsByTags"_s);
    QString fullPath = u"/pet/findByTags"_s;
    int queryParamCounter = 0;
    {
        [[maybe_unused]] QString paramString;

        SerializationFlags flags;
        flags.setFlag(SerializationFlag::Object, false || false);
        flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
        flags.setFlag(SerializationFlag::Explode, false);

        SerializationOptions opts;
        opts.style = "form"sv.empty() ? "form" : "form";
        opts.prefix = getParamStylePrefix(opts.style);
        opts.delimiter = getParamStyleDelimiter(opts.style, flags);
        opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
        opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"tags"_s), flags);
        opts.flags = flags;
        if ((fullPath.indexOf(u'?') != fullPath.size() - 1) && (queryParamCounter == 0))
            fullPath.append(opts.prefix);
        {
            if (queryParamCounter > 0)
                fullPath.append(u'&');
            fullPath.append(serializeArrayValue(tags, opts));
            queryParamCounter++;
        }
    }
    QOAIHttpRequestInput input(fullPath, "GET"_L1);
    QByteArray requestContent;
    QNetworkRequest request
        = QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
                                                         networkRequestFactory(),
                                                         responseCompressionEnabled(),
                                                         requestCompressionEnabled());
    QNetworkReply *reply = execute(input, request, requestContent);
    if (reply != nullptr) {
        reply->setParent(this);
        setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
        connect(reply, &QNetworkReply::finished, this, [this, reply] {
            findPetsByTagsCallback(QRestReply(reply));
        });
        connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
            if (reply) {
                emit findPetsByTagsErrorOccurred(reply->error(), reply->errorString());
                QOAICallerInfo callerInfo = takeCallerInfo(reply);
                if (callerInfo.slot) {
                    QList<Pet> empty;
                    QRestReply restRepl(reply);
                    void *argv[] = { nullptr, &restRepl, &empty };
                    QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
                    callerInfo.slot->call(context, argv);
                }
            }
        });
    }
}

void PetApi::findPetsByTagsCallback(const QRestReply &reply)
{
    auto netReply = reply.networkReply();
    if (netReply)
        netReply->disconnect(this);
    if (!reply.isSuccess())
        return;

    const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory());
    QList<Pet> output;
    const QJsonDocument doc = QJsonDocument::fromJson(response);
    if (!doc.isNull() && doc.isArray()) {
        const QJsonArray jsonArray = doc.array();
        for (const QJsonValue &obj : jsonArray) {
            Pet val;
            const bool ok = ::QtOpenApiCommon::fromJsonValue(val, obj);
            if (!ok)
                qWarning("%s: Failed to convert QJsonValue to Pet.", Q_FUNC_INFO);
            output.append(val);
        }
    } else {
        qWarning("%s: Failed to parse the response as a JSON array.", Q_FUNC_INFO);
    }
    // Check if callback is provided
    QOAICallerInfo callerInfo = takeCallerInfo(netReply);
    if (callerInfo.slot) {
        void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
        QObject *context = callerInfo.contextObject
                        ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
        callerInfo.slot->call(context, argv);
    }
    emit findPetsByTagsFinished(output);
}

/**
* \fn void PetApi::findPetsImageById(const qint64 &petId)
* 'findPetsImageById' operation sends the request to a server.
* The request parameters are defined by a specification file.

* @param[in] petId qint64 [required]
*/

/**
* \fn template < Functor, > void PetApi::findPetsImageById(const qint64 &petId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'findPetsImageById' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
*    findPetsImageById(petId, this, [&](const QRestReply &reply, const QString &summary) { if (reply.isSuccess()) ... });
* \endcode

* @param[in] petId qint64 [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/

/**
* \fn void PetApi::findPetsImageByIdCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by findPetsImageByIdFinished() or
* being returned as a callback parameter of findPetsImageById() request.
* @param[in] reply const QRestReply &
*/

/**
* \fn void PetApi::findPetsImageByIdWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the findPetsImageById() operation request.

* @param[in] petId qint64 [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void PetApi::findPetsImageByIdWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
    QtPrivate::SlotObjUniquePtr slotPtr(slot);
    setBaseServerUrl(u"findPetsImageById"_s);
    QString fullPath = u"/pet/findPetsImageById"_s;
    int queryParamCounter = 0;
    {
        [[maybe_unused]] QString paramString;

        SerializationFlags flags;
        flags.setFlag(SerializationFlag::Object, false || false);
        flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
        flags.setFlag(SerializationFlag::Explode, true);

        SerializationOptions opts;
        opts.style = "form"sv.empty() ? "form" : "form";
        opts.prefix = getParamStylePrefix(opts.style);
        opts.delimiter = getParamStyleDelimiter(opts.style, flags);
        opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
        opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"petId"_s), flags);
        opts.flags = flags;
        paramString = opts.suffix;
        if ((fullPath.indexOf(u'?') != fullPath.size() - 1) && (queryParamCounter == 0))
            fullPath.append(opts.prefix);
        {
            if (queryParamCounter > 0)
                fullPath.append(u'&');
            fullPath.append(opts.suffix + QUrl::toPercentEncoding(::QtOpenApiCommon::toStringValue(petId)));
            queryParamCounter++;
        }
    }
    QOAIHttpRequestInput input(fullPath, "GET"_L1);
    QByteArray requestContent;
    QNetworkRequest request
        = QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
                                                         networkRequestFactory(),
                                                         responseCompressionEnabled(),
                                                         requestCompressionEnabled());
    QNetworkReply *reply = execute(input, request, requestContent);
    if (reply != nullptr) {
        reply->setParent(this);
        setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
        connect(reply, &QNetworkReply::finished, this, [this, reply] {
            findPetsImageByIdCallback(QRestReply(reply));
        });
        connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
            if (reply) {
                emit findPetsImageByIdErrorOccurred(reply->error(), reply->errorString());
                QOAICallerInfo callerInfo = takeCallerInfo(reply);
                if (callerInfo.slot) {
                    QString empty;
                    QRestReply restRepl(reply);
                    void *argv[] = { nullptr, &restRepl, &empty };
                    QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
                    callerInfo.slot->call(context, argv);
                }
            }
        });
    }
}

void PetApi::findPetsImageByIdCallback(const QRestReply &reply)
{
    auto netReply = reply.networkReply();
    if (netReply)
        netReply->disconnect(this);
    if (!reply.isSuccess())
        return;

    const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory());
    QString output;
    const bool ok = ::QtOpenApiCommon::fromByteArray(response, output);
    if (!ok)
        qWarning("%s: Failed to convert the response to QString.", Q_FUNC_INFO);
    // Check if callback is provided
    QOAICallerInfo callerInfo = takeCallerInfo(netReply);
    if (callerInfo.slot) {
        void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
        QObject *context = callerInfo.contextObject
                        ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
        callerInfo.slot->call(context, argv);
    }
    emit findPetsImageByIdFinished(output);
}

/**
* \fn void PetApi::getJsonFile(const qint64 &petId)
* 'getJsonFile' operation sends the request to a server.
* The request parameters are defined by a specification file.

* @param[in] petId qint64 [required]
*/

/**
* \fn template < Functor, > void PetApi::getJsonFile(const qint64 &petId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'getJsonFile' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
*    getJsonFile(petId, this, [&](const QRestReply &reply, const QOAIHttpFileElement &summary) { if (reply.isSuccess()) ... });
* \endcode

* @param[in] petId qint64 [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/

/**
* \fn void PetApi::getJsonFileCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by getJsonFileFinished() or
* being returned as a callback parameter of getJsonFile() request.
* @param[in] reply const QRestReply &
*/

/**
* \fn void PetApi::getJsonFileWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the getJsonFile() operation request.

* @param[in] petId qint64 [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void PetApi::getJsonFileWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
    QtPrivate::SlotObjUniquePtr slotPtr(slot);
    setBaseServerUrl(u"getJsonFile"_s);
    QString fullPath = u"/pet/{petId}/uploadImage"_s;
    {
        QString petIdPathParam = u"{%1}"_s.arg(u"petId"_s);

        SerializationFlags flags;
        flags.setFlag(SerializationFlag::Object, false || false);
        flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
        flags.setFlag(SerializationFlag::Explode, false);

        SerializationOptions opts;
        opts.style = "simple"sv.empty() ? "simple" : "simple";
        opts.prefix = getParamStylePrefix(opts.style);
        opts.delimiter = getParamStyleDelimiter(opts.style, flags);
        opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
        opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"petId"_s), flags);
        opts.flags = flags;
        QString paramString = opts.prefix + opts.suffix;
        paramString += QUrl::toPercentEncoding(::QtOpenApiCommon::toStringValue(petId));
        // In case style=matrix and paramString is empty due to any reasons,
        // we serialize it like undefined value and delete '='.
        // Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
        if ((paramString == opts.prefix + opts.suffix) && opts.style == "matrix")
            paramString.chop(1);
        fullPath.replace(petIdPathParam, paramString);
    }

    QOAIHttpRequestInput input(fullPath, "GET"_L1);
    QByteArray requestContent;
    QNetworkRequest request
        = QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
                                                         networkRequestFactory(),
                                                         responseCompressionEnabled(),
                                                         requestCompressionEnabled());
    QNetworkReply *reply = execute(input, request, requestContent);
    if (reply != nullptr) {
        reply->setParent(this);
        setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
        connect(reply, &QNetworkReply::finished, this, [this, reply] {
            getJsonFileCallback(QRestReply(reply));
        });
        connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
            if (reply) {
                emit getJsonFileErrorOccurred(reply->error(), reply->errorString());
                QOAICallerInfo callerInfo = takeCallerInfo(reply);
                if (callerInfo.slot) {
                    QOAIHttpFileElement empty;
                    QRestReply restRepl(reply);
                    void *argv[] = { nullptr, &restRepl, &empty };
                    QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
                    callerInfo.slot->call(context, argv);
                }
            }
        });
    }
}

void PetApi::getJsonFileCallback(const QRestReply &reply)
{
    auto netReply = reply.networkReply();
    if (netReply)
        netReply->disconnect(this);
    if (!reply.isSuccess())
        return;

    QMap<QString, QOAIHttpFileElement> responseFiles;
    const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory(), &responseFiles, fileConflictPolicy());
    QOAIHttpFileElement output = QOAIHttpRequestWorker::getHttpFileElement(responseFiles);
    // Check if callback is provided
    QOAICallerInfo callerInfo = takeCallerInfo(netReply);
    if (callerInfo.slot) {
        void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
        QObject *context = callerInfo.contextObject
                        ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
        callerInfo.slot->call(context, argv);
    }
    emit getJsonFileFinished(output);
}

/**
* \fn void PetApi::getPetById(const qint64 &petId)
* 'getPetById' operation sends the request to a server.
* The request parameters are defined by a specification file.

* @param[in] petId qint64 [required]
*/

/**
* \fn template < Functor, > void PetApi::getPetById(const qint64 &petId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'getPetById' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
*    getPetById(petId, this, [&](const QRestReply &reply, const Pet &summary) { if (reply.isSuccess()) ... });
* \endcode

* @param[in] petId qint64 [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/

/**
* \fn void PetApi::getPetByIdCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by getPetByIdFinished() or
* being returned as a callback parameter of getPetById() request.
* @param[in] reply const QRestReply &
*/

/**
* \fn void PetApi::getPetByIdWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the getPetById() operation request.

* @param[in] petId qint64 [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void PetApi::getPetByIdWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
    QtPrivate::SlotObjUniquePtr slotPtr(slot);
    setBaseServerUrl(u"getPetById"_s);
    QString fullPath = u"/pet/{petId}"_s;
    if (const auto key = apiKey("api_key"_L1); key.has_value()) {
        setHeader("api_key"_L1, *key);
    }
    {
        QString petIdPathParam = u"{%1}"_s.arg(u"petId"_s);

        SerializationFlags flags;
        flags.setFlag(SerializationFlag::Object, false || false);
        flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
        flags.setFlag(SerializationFlag::Explode, false);

        SerializationOptions opts;
        opts.style = "simple"sv.empty() ? "simple" : "simple";
        opts.prefix = getParamStylePrefix(opts.style);
        opts.delimiter = getParamStyleDelimiter(opts.style, flags);
        opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
        opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"petId"_s), flags);
        opts.flags = flags;
        QString paramString = opts.prefix + opts.suffix;
        paramString += QUrl::toPercentEncoding(::QtOpenApiCommon::toStringValue(petId));
        // In case style=matrix and paramString is empty due to any reasons,
        // we serialize it like undefined value and delete '='.
        // Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
        if ((paramString == opts.prefix + opts.suffix) && opts.style == "matrix")
            paramString.chop(1);
        fullPath.replace(petIdPathParam, paramString);
    }

    QOAIHttpRequestInput input(fullPath, "GET"_L1);
    QByteArray requestContent;
    QNetworkRequest request
        = QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
                                                         networkRequestFactory(),
                                                         responseCompressionEnabled(),
                                                         requestCompressionEnabled());
    QNetworkReply *reply = execute(input, request, requestContent);
    if (reply != nullptr) {
        reply->setParent(this);
        setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
        connect(reply, &QNetworkReply::finished, this, [this, reply] {
            getPetByIdCallback(QRestReply(reply));
        });
        connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
            if (reply) {
                emit getPetByIdErrorOccurred(reply->error(), reply->errorString());
                QOAICallerInfo callerInfo = takeCallerInfo(reply);
                if (callerInfo.slot) {
                    Pet empty;
                    QRestReply restRepl(reply);
                    void *argv[] = { nullptr, &restRepl, &empty };
                    QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
                    callerInfo.slot->call(context, argv);
                }
            }
        });
    }
}

void PetApi::getPetByIdCallback(const QRestReply &reply)
{
    auto netReply = reply.networkReply();
    if (netReply)
        netReply->disconnect(this);
    if (!reply.isSuccess())
        return;

    const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory());
    Pet output(response);
    // Check if callback is provided
    QOAICallerInfo callerInfo = takeCallerInfo(netReply);
    if (callerInfo.slot) {
        void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
        QObject *context = callerInfo.contextObject
                        ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
        callerInfo.slot->call(context, argv);
    }
    emit getPetByIdFinished(output);
}

/**
* \fn void PetApi::updatePet(const Pet &pet)
* 'updatePet' operation sends the request to a server.
* The request parameters are defined by a specification file.

* @param[in] pet Pet [required]
*/

/**
* \fn template < Functor, > void PetApi::updatePet(const Pet &pet, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'updatePet' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
*    updatePet(pet, this, [&](const QRestReply &reply, const Pet &summary) { if (reply.isSuccess()) ... });
* \endcode

* @param[in] pet Pet [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/

/**
* \fn void PetApi::updatePetCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by updatePetFinished() or
* being returned as a callback parameter of updatePet() request.
* @param[in] reply const QRestReply &
*/

/**
* \fn void PetApi::updatePetWithDataImpl(const Pet &pet, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the updatePet() operation request.

* @param[in] pet Pet [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void PetApi::updatePetWithDataImpl(const Pet &pet, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
    QtPrivate::SlotObjUniquePtr slotPtr(slot);
    setBaseServerUrl(u"updatePet"_s);
    QString fullPath = u"/pet"_s;
    if (const auto key = apiKey(u"api_key_query"_s); key.has_value()) {
        if (fullPath.indexOf(u'?') > 0)
            fullPath.append(u'&');
        else
            fullPath.append(u'?');
        fullPath.append(u"api_key_query="_s).append(*key);
    }

    QOAIHttpRequestInput input(fullPath, "PUT"_L1);
    input.headers().replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
    {
        const QByteArray output = pet.asJson().toUtf8();
        input.setRequestBody(output);
    }
    QByteArray requestContent;
    QNetworkRequest request
        = QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
                                                         networkRequestFactory(),
                                                         responseCompressionEnabled(),
                                                         requestCompressionEnabled());
    QNetworkReply *reply = execute(input, request, requestContent);
    if (reply != nullptr) {
        reply->setParent(this);
        setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
        connect(reply, &QNetworkReply::finished, this, [this, reply] {
            updatePetCallback(QRestReply(reply));
        });
        connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
            if (reply) {
                emit updatePetErrorOccurred(reply->error(), reply->errorString());
                QOAICallerInfo callerInfo = takeCallerInfo(reply);
                if (callerInfo.slot) {
                    Pet empty;
                    QRestReply restRepl(reply);
                    void *argv[] = { nullptr, &restRepl, &empty };
                    QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
                    callerInfo.slot->call(context, argv);
                }
            }
        });
    }
}

void PetApi::updatePetCallback(const QRestReply &reply)
{
    auto netReply = reply.networkReply();
    if (netReply)
        netReply->disconnect(this);
    if (!reply.isSuccess())
        return;

    const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory());
    Pet output(response);
    // Check if callback is provided
    QOAICallerInfo callerInfo = takeCallerInfo(netReply);
    if (callerInfo.slot) {
        void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
        QObject *context = callerInfo.contextObject
                        ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
        callerInfo.slot->call(context, argv);
    }
    emit updatePetFinished(output);
}

/**
* \fn void PetApi::updatePetWithForm(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &name = QtOpenApiCommon::OptionalParameter<QString>(), const QtOpenApiCommon::OptionalParameter<QString> &status = QtOpenApiCommon::OptionalParameter<QString>())
* 'updatePetWithForm' operation sends the request to a server.
* The request parameters are defined by a specification file.

* @param[in] petId qint64 [required]
* @param[in] name QString [optional]
* @param[in] status QString [optional]
*/

/**
* \fn template < Functor, > void PetApi::updatePetWithForm(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &name = QtOpenApiCommon::OptionalParameter<QString>(), const QtOpenApiCommon::OptionalParameter<QString> &status = QtOpenApiCommon::OptionalParameter<QString>(), const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'updatePetWithForm' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
*    updatePetWithForm(petId, name, status, this, [&](const QRestReply &reply) { if (reply.isSuccess()) ... });
* \endcode

* @param[in] petId qint64 [required]
* @param[in] name QString [optional]
* @param[in] status QString [optional]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/

/**
* \fn void PetApi::updatePetWithFormCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by updatePetWithFormFinished() or
* being returned as a callback parameter of updatePetWithForm() request.
* @param[in] reply const QRestReply &
*/

/**
* \fn void PetApi::updatePetWithFormWithDataImpl(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &name, const QtOpenApiCommon::OptionalParameter<QString> &status, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the updatePetWithForm() operation request.

* @param[in] petId qint64 [required]
* @param[in] name QString [optional]
* @param[in] status QString [optional]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void PetApi::updatePetWithFormWithDataImpl(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &name, const QtOpenApiCommon::OptionalParameter<QString> &status, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
    QtPrivate::SlotObjUniquePtr slotPtr(slot);
    setBaseServerUrl(u"updatePetWithForm"_s);
    QString fullPath = u"/pet/{petId}"_s;
    {
        QString petIdPathParam = u"{%1}"_s.arg(u"petId"_s);

        SerializationFlags flags;
        flags.setFlag(SerializationFlag::Object, false || false);
        flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
        flags.setFlag(SerializationFlag::Explode, false);

        SerializationOptions opts;
        opts.style = "simple"sv.empty() ? "simple" : "simple";
        opts.prefix = getParamStylePrefix(opts.style);
        opts.delimiter = getParamStyleDelimiter(opts.style, flags);
        opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
        opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"petId"_s), flags);
        opts.flags = flags;
        QString paramString = opts.prefix + opts.suffix;
        paramString += QUrl::toPercentEncoding(::QtOpenApiCommon::toStringValue(petId));
        // In case style=matrix and paramString is empty due to any reasons,
        // we serialize it like undefined value and delete '='.
        // Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
        if ((paramString == opts.prefix + opts.suffix) && opts.style == "matrix")
            paramString.chop(1);
        fullPath.replace(petIdPathParam, paramString);
    }

    QOAIHttpRequestInput input(fullPath, "POST"_L1);
    input.headers().replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/x-www-form-urlencoded"_L1);
    input.setIsFormData(true);
    input.setVariableLayout(input.httpMethod() == "GET"_L1 || input.httpMethod() == "HEAD"_L1
                       ? QOAIHttpRequestInput::VariableLayout::Address
                       : QOAIHttpRequestInput::VariableLayout::UrlEncoded);
    if (name.hasValue()) {
        QString contentType;
        using VT = std::decay_t<decltype(name.value())>;
        input.addFieldHeaders(u"name"_s, addContentField<VT>(contentType));
        input.addVariable(u"name"_s, ::QtOpenApiCommon::serializeMediaTypeContentField(contentType, name.value()));
    }
    if (status.hasValue()) {
        QString contentType;
        using VT = std::decay_t<decltype(status.value())>;
        input.addFieldHeaders(u"status"_s, addContentField<VT>(contentType));
        input.addVariable(u"status"_s, ::QtOpenApiCommon::serializeMediaTypeContentField(contentType, status.value()));
    }
    QByteArray requestContent;
    QNetworkRequest request
        = QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
                                                         networkRequestFactory(),
                                                         responseCompressionEnabled(),
                                                         requestCompressionEnabled());
    QNetworkReply *reply = execute(input, request, requestContent);
    if (reply != nullptr) {
        reply->setParent(this);
        setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
        connect(reply, &QNetworkReply::finished, this, [this, reply] {
            updatePetWithFormCallback(QRestReply(reply));
        });
        connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
            if (reply) {
                emit updatePetWithFormErrorOccurred(reply->error(), reply->errorString());
                QOAICallerInfo callerInfo = takeCallerInfo(reply);
                if (callerInfo.slot) {
                    QRestReply restRepl(reply);
                    void *argv[] = { nullptr, &restRepl };
                    QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
                    callerInfo.slot->call(context, argv);
                }
            }
        });
    }
}

void PetApi::updatePetWithFormCallback(const QRestReply &reply)
{
    auto netReply = reply.networkReply();
    if (netReply)
        netReply->disconnect(this);
    if (!reply.isSuccess())
        return;

    // Check if callback is provided
    QOAICallerInfo callerInfo = takeCallerInfo(netReply);
    if (callerInfo.slot) {
        void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
        QObject *context = callerInfo.contextObject
                        ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
        callerInfo.slot->call(context, argv);
    }
    emit updatePetWithFormFinished();
}

/**
* \fn void PetApi::uploadFile(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &additionalMetadata = QtOpenApiCommon::OptionalParameter<QString>(), const QtOpenApiCommon::OptionalParameter<QOAIHttpFileElement> &file = QtOpenApiCommon::OptionalParameter<QOAIHttpFileElement>())
* 'uploadFile' operation sends the request to a server.
* The request parameters are defined by a specification file.

* @param[in] petId qint64 [required]
* @param[in] additionalMetadata QString [optional]
* @param[in] file QOAIHttpFileElement [optional]
*/

/**
* \fn template < Functor, > void PetApi::uploadFile(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &additionalMetadata = QtOpenApiCommon::OptionalParameter<QString>(), const QtOpenApiCommon::OptionalParameter<QOAIHttpFileElement> &file = QtOpenApiCommon::OptionalParameter<QOAIHttpFileElement>(), const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'uploadFile' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
*    uploadFile(petId, additionalMetadata, file, this, [&](const QRestReply &reply, const ApiResponse &summary) { if (reply.isSuccess()) ... });
* \endcode

* @param[in] petId qint64 [required]
* @param[in] additionalMetadata QString [optional]
* @param[in] file QOAIHttpFileElement [optional]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/

/**
* \fn void PetApi::uploadFileCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by uploadFileFinished() or
* being returned as a callback parameter of uploadFile() request.
* @param[in] reply const QRestReply &
*/

/**
* \fn void PetApi::uploadFileWithDataImpl(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &additionalMetadata, const QtOpenApiCommon::OptionalParameter<QOAIHttpFileElement> &file, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the uploadFile() operation request.

* @param[in] petId qint64 [required]
* @param[in] additionalMetadata QString [optional]
* @param[in] file QOAIHttpFileElement [optional]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void PetApi::uploadFileWithDataImpl(const qint64 &petId, const QtOpenApiCommon::OptionalParameter<QString> &additionalMetadata, const QtOpenApiCommon::OptionalParameter<QOAIHttpFileElement> &file, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
    QtPrivate::SlotObjUniquePtr slotPtr(slot);
    setBaseServerUrl(u"uploadFile"_s);
    QString fullPath = u"/pet/{petId}/uploadImage"_s;
    {
        QString petIdPathParam = u"{%1}"_s.arg(u"petId"_s);

        SerializationFlags flags;
        flags.setFlag(SerializationFlag::Object, false || false);
        flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
        flags.setFlag(SerializationFlag::Explode, false);

        SerializationOptions opts;
        opts.style = "simple"sv.empty() ? "simple" : "simple";
        opts.prefix = getParamStylePrefix(opts.style);
        opts.delimiter = getParamStyleDelimiter(opts.style, flags);
        opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
        opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"petId"_s), flags);
        opts.flags = flags;
        QString paramString = opts.prefix + opts.suffix;
        paramString += QUrl::toPercentEncoding(::QtOpenApiCommon::toStringValue(petId));
        // In case style=matrix and paramString is empty due to any reasons,
        // we serialize it like undefined value and delete '='.
        // Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
        if ((paramString == opts.prefix + opts.suffix) && opts.style == "matrix")
            paramString.chop(1);
        fullPath.replace(petIdPathParam, paramString);
    }

    QOAIHttpRequestInput input(fullPath, "POST"_L1);
    input.headers().replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "multipart/form-data"_L1);
    input.setIsFormData(true);
    input.setVariableLayout(QOAIHttpRequestInput::VariableLayout::Multipart);
    if (additionalMetadata.hasValue()) {
        QString contentType;
        using VT = std::decay_t<decltype(additionalMetadata.value())>;
        input.addFieldHeaders(u"additionalMetadata"_s, addContentField<VT>(contentType));
        input.addVariable(u"additionalMetadata"_s, ::QtOpenApiCommon::serializeMediaTypeContentField(contentType, additionalMetadata.value()));
    }
    if (file.hasValue()) {
        QString contentType;
        input.addFile(u"file"_s, file.value().filename(), contentType);
    }
    QByteArray requestContent;
    QNetworkRequest request
        = QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
                                                         networkRequestFactory(),
                                                         responseCompressionEnabled(),
                                                         requestCompressionEnabled());
    QNetworkReply *reply = execute(input, request, requestContent);
    if (reply != nullptr) {
        reply->setParent(this);
        setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
        connect(reply, &QNetworkReply::finished, this, [this, reply] {
            uploadFileCallback(QRestReply(reply));
        });
        connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
            if (reply) {
                emit uploadFileErrorOccurred(reply->error(), reply->errorString());
                QOAICallerInfo callerInfo = takeCallerInfo(reply);
                if (callerInfo.slot) {
                    ApiResponse empty;
                    QRestReply restRepl(reply);
                    void *argv[] = { nullptr, &restRepl, &empty };
                    QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
                    callerInfo.slot->call(context, argv);
                }
            }
        });
    }
}

void PetApi::uploadFileCallback(const QRestReply &reply)
{
    auto netReply = reply.networkReply();
    if (netReply)
        netReply->disconnect(this);
    if (!reply.isSuccess())
        return;

    const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory());
    ApiResponse output(response);
    // Check if callback is provided
    QOAICallerInfo callerInfo = takeCallerInfo(netReply);
    if (callerInfo.slot) {
        void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
        QObject *context = callerInfo.contextObject
                        ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
        callerInfo.slot->call(context, argv);
    }
    emit uploadFileFinished(output);
}

} // namespace QtOpenAPI
