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

#include "JHybridAppleAuthSpec.hpp"

// Forward declaration of `AppleAuthCredential` to properly resolve imports.
namespace margelo::nitro::appleauth { struct AppleAuthCredential; }
// Forward declaration of `AppleAuthOptions` to properly resolve imports.
namespace margelo::nitro::appleauth { struct AppleAuthOptions; }
// Forward declaration of `AppleAuthOperation` to properly resolve imports.
namespace margelo::nitro::appleauth { enum class AppleAuthOperation; }
// Forward declaration of `AppleAuthScopes` to properly resolve imports.
namespace margelo::nitro::appleauth { enum class AppleAuthScopes; }

#include <NitroModules/Promise.hpp>
#include <optional>
#include "AppleAuthCredential.hpp"
#include <NitroModules/JPromise.hpp>
#include "JAppleAuthCredential.hpp"
#include <string>
#include "AppleAuthOptions.hpp"
#include "JAppleAuthOptions.hpp"
#include "AppleAuthOperation.hpp"
#include "JAppleAuthOperation.hpp"
#include <vector>
#include "AppleAuthScopes.hpp"
#include "JAppleAuthScopes.hpp"

namespace margelo::nitro::appleauth {

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

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

  size_t JHybridAppleAuthSpec::getExternalMemorySize() noexcept {
    static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
    return method(_javaPart);
  }

  // Properties
  

  // Methods
  std::shared_ptr<Promise<std::optional<AppleAuthCredential>>> JHybridAppleAuthSpec::signIn(const AppleAuthOptions& options) {
    static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JAppleAuthOptions> /* options */)>("signIn");
    auto __result = method(_javaPart, JAppleAuthOptions::fromCpp(options));
    return [&]() {
      auto __promise = Promise<std::optional<AppleAuthCredential>>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JAppleAuthCredential>(__boxedResult);
        __promise->resolve(__result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt);
      });
      __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::appleauth
