///
/// JHybridNitroGoogleSsoSpec.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///

#include "JHybridNitroGoogleSsoSpec.hpp"

// Forward declaration of `NitroGoogleUserInfo` to properly resolve imports.
namespace margelo::nitro::nitrogooglesso { struct NitroGoogleUserInfo; }
// Forward declaration of `NitroGoogleSSOConfig` to properly resolve imports.
namespace margelo::nitro::nitrogooglesso { struct NitroGoogleSSOConfig; }

#include <NitroModules/Null.hpp>
#include "NitroGoogleUserInfo.hpp"
#include <variant>
#include <NitroModules/Promise.hpp>
#include <NitroModules/JPromise.hpp>
#include "JVariant_NullType_NitroGoogleUserInfo.hpp"
#include <NitroModules/JNull.hpp>
#include "JNitroGoogleUserInfo.hpp"
#include <string>
#include <optional>
#include <NitroModules/JUnit.hpp>
#include "NitroGoogleSSOConfig.hpp"
#include "JNitroGoogleSSOConfig.hpp"

namespace margelo::nitro::nitrogooglesso {

  std::shared_ptr<JHybridNitroGoogleSsoSpec> JHybridNitroGoogleSsoSpec::JavaPart::getJHybridNitroGoogleSsoSpec() {
    auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
    auto castHybridObject = std::dynamic_pointer_cast<JHybridNitroGoogleSsoSpec>(hybridObject);
    if (castHybridObject == nullptr) [[unlikely]] {
      throw std::runtime_error("Failed to downcast JHybridObject to JHybridNitroGoogleSsoSpec!");
    }
    return castHybridObject;
  }

  jni::local_ref<JHybridNitroGoogleSsoSpec::CxxPart::jhybriddata> JHybridNitroGoogleSsoSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
    return makeCxxInstance(jThis);
  }

  std::shared_ptr<JHybridObject> JHybridNitroGoogleSsoSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
    auto castJavaPart = jni::dynamic_ref_cast<JHybridNitroGoogleSsoSpec::JavaPart>(javaPart);
    if (castJavaPart == nullptr) [[unlikely]] {
      throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridNitroGoogleSsoSpec::JavaPart!");
    }
    return std::make_shared<JHybridNitroGoogleSsoSpec>(castJavaPart);
  }

  void JHybridNitroGoogleSsoSpec::CxxPart::registerNatives() {
    registerHybrid({
      makeNativeMethod("initHybrid", JHybridNitroGoogleSsoSpec::CxxPart::initHybrid),
    });
  }

  // Properties
  

  // Methods
  void JHybridNitroGoogleSsoSpec::configure(const NitroGoogleSSOConfig& config) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JNitroGoogleSSOConfig> /* config */)>("configure");
    method(_javaPart, JNitroGoogleSSOConfig::fromCpp(config));
  }
  std::shared_ptr<Promise<std::variant<nitro::NullType, NitroGoogleUserInfo>>> JHybridNitroGoogleSsoSpec::signIn() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("signIn");
    auto __result = method(_javaPart);
    return [&]() {
      auto __promise = Promise<std::variant<nitro::NullType, NitroGoogleUserInfo>>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JVariant_NullType_NitroGoogleUserInfo>(__boxedResult);
        __promise->resolve(__result->toCpp());
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  std::shared_ptr<Promise<std::variant<nitro::NullType, NitroGoogleUserInfo>>> JHybridNitroGoogleSsoSpec::oneTapSignIn() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("oneTapSignIn");
    auto __result = method(_javaPart);
    return [&]() {
      auto __promise = Promise<std::variant<nitro::NullType, NitroGoogleUserInfo>>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JVariant_NullType_NitroGoogleUserInfo>(__boxedResult);
        __promise->resolve(__result->toCpp());
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  std::shared_ptr<Promise<void>> JHybridNitroGoogleSsoSpec::signOut() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("signOut");
    auto __result = method(_javaPart);
    return [&]() {
      auto __promise = Promise<void>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
        __promise->resolve();
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  std::shared_ptr<Promise<std::variant<nitro::NullType, NitroGoogleUserInfo>>> JHybridNitroGoogleSsoSpec::getCurrentUser() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getCurrentUser");
    auto __result = method(_javaPart);
    return [&]() {
      auto __promise = Promise<std::variant<nitro::NullType, NitroGoogleUserInfo>>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JVariant_NullType_NitroGoogleUserInfo>(__boxedResult);
        __promise->resolve(__result->toCpp());
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }

} // namespace margelo::nitro::nitrogooglesso
