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

#include "JHybridOneAppleAuthSpec.hpp"

// Forward declaration of `AppleAuthResult` to properly resolve imports.
namespace margelo::nitro::one { struct AppleAuthResult; }
// Forward declaration of `AppleAuthResultType` to properly resolve imports.
namespace margelo::nitro::one { enum class AppleAuthResultType; }
// Forward declaration of `AppleAuthCredential` to properly resolve imports.
namespace margelo::nitro::one { struct AppleAuthCredential; }
// Forward declaration of `AppleAuthFullName` to properly resolve imports.
namespace margelo::nitro::one { struct AppleAuthFullName; }
// Forward declaration of `AppleRealUserStatus` to properly resolve imports.
namespace margelo::nitro::one { enum class AppleRealUserStatus; }
// Forward declaration of `AppleCredentialState` to properly resolve imports.
namespace margelo::nitro::one { enum class AppleCredentialState; }
// Forward declaration of `AppleAuthSignInOptions` to properly resolve imports.
namespace margelo::nitro::one { struct AppleAuthSignInOptions; }
// Forward declaration of `AppleAuthScope` to properly resolve imports.
namespace margelo::nitro::one { enum class AppleAuthScope; }

#include "AppleAuthResult.hpp"
#include <NitroModules/Promise.hpp>
#include <NitroModules/JPromise.hpp>
#include "JAppleAuthResult.hpp"
#include "AppleAuthResultType.hpp"
#include "JAppleAuthResultType.hpp"
#include "AppleAuthCredential.hpp"
#include <optional>
#include "JAppleAuthCredential.hpp"
#include <string>
#include "AppleAuthFullName.hpp"
#include "JAppleAuthFullName.hpp"
#include "AppleRealUserStatus.hpp"
#include "JAppleRealUserStatus.hpp"
#include "AppleCredentialState.hpp"
#include "JAppleCredentialState.hpp"
#include "AppleAuthSignInOptions.hpp"
#include "JAppleAuthSignInOptions.hpp"
#include "AppleAuthScope.hpp"
#include <vector>
#include "JAppleAuthScope.hpp"

namespace margelo::nitro::one {

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

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

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

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

  // Properties
  

  // Methods
  bool JHybridOneAppleAuthSpec::isAvailable() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isAvailable");
    auto __result = method(_javaPart);
    return static_cast<bool>(__result);
  }
  std::shared_ptr<Promise<AppleAuthResult>> JHybridOneAppleAuthSpec::signIn(const AppleAuthSignInOptions& options) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JAppleAuthSignInOptions> /* options */)>("signIn");
    auto __result = method(_javaPart, JAppleAuthSignInOptions::fromCpp(options));
    return [&]() {
      auto __promise = Promise<AppleAuthResult>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JAppleAuthResult>(__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<AppleCredentialState>> JHybridOneAppleAuthSpec::getCredentialState(const std::string& user) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* user */)>("getCredentialState");
    auto __result = method(_javaPart, jni::make_jstring(user));
    return [&]() {
      auto __promise = Promise<AppleCredentialState>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JAppleCredentialState>(__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::one
