/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */

#include "qmltestservice_client.grpc.qpb.h"

namespace qtgrpc::tests {
namespace TestService {
using namespace Qt::StringLiterals;

QmlClient::QmlClient(QObject *parent)
    : Client(parent)
{
}


void QmlClient::testMethod(const qtgrpc::tests::SimpleStringMessage &arg, const QJSValue &callback, const QJSValue &errorCallback,const QGrpcCallOptions &options)
{
    if (!callback.isCallable()) {
        qWarning() << "Unable to call QmlClient::testMethod, callback is not callable";
        return;
    }

    QJSEngine *jsEngine = qjsEngine(this);
    if (jsEngine == nullptr) {
        qWarning() << "Unable to call QmlClient::testMethod, it's only callable from JS engine context";
        return;
    }

    std::shared_ptr<QGrpcCallReply> reply = call<qtgrpc::tests::SimpleStringMessage>("testMethod"_L1, arg, options);
    reply->subscribe(jsEngine, [reply, callback, jsEngine]() {
        auto result = reply->read<qtgrpc::tests::SimpleStringMessage>();
        callback.call(QJSValueList{jsEngine->toScriptValue(result)});
    }, [errorCallback, jsEngine](const QGrpcStatus &status) {
        errorCallback.call(QJSValueList{jsEngine->toScriptValue(status)});
    });
}

} // namespace TestService
} // namespace qtgrpc::tests

