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

#include "JHybridInappbrowserNitroSpec.hpp"

// Forward declaration of `InAppBrowserResult` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { struct InAppBrowserResult; }
// Forward declaration of `BrowserResultType` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { enum class BrowserResultType; }
// Forward declaration of `InAppBrowserAuthResult` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { struct InAppBrowserAuthResult; }
// Forward declaration of `InAppBrowserOptions` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { struct InAppBrowserOptions; }
// Forward declaration of `DismissButtonStyle` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { enum class DismissButtonStyle; }
// Forward declaration of `DynamicColor` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { struct DynamicColor; }
// Forward declaration of `StatusBarStyle` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { enum class StatusBarStyle; }
// Forward declaration of `ModalPresentationStyle` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { enum class ModalPresentationStyle; }
// Forward declaration of `ModalTransitionStyle` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { enum class ModalTransitionStyle; }
// Forward declaration of `UserInterfaceStyle` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { enum class UserInterfaceStyle; }
// Forward declaration of `FormSheetContentSize` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { struct FormSheetContentSize; }
// Forward declaration of `BrowserShareState` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { enum class BrowserShareState; }
// Forward declaration of `BrowserColorScheme` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { enum class BrowserColorScheme; }
// Forward declaration of `BrowserAnimations` to properly resolve imports.
namespace margelo::nitro::inappbrowsernitro { struct BrowserAnimations; }

#include <NitroModules/Promise.hpp>
#include <NitroModules/JPromise.hpp>
#include "InAppBrowserResult.hpp"
#include "JInAppBrowserResult.hpp"
#include "BrowserResultType.hpp"
#include "JBrowserResultType.hpp"
#include <string>
#include <optional>
#include "InAppBrowserAuthResult.hpp"
#include "JInAppBrowserAuthResult.hpp"
#include <NitroModules/JUnit.hpp>
#include "InAppBrowserOptions.hpp"
#include "JInAppBrowserOptions.hpp"
#include "DismissButtonStyle.hpp"
#include "JDismissButtonStyle.hpp"
#include "DynamicColor.hpp"
#include "JDynamicColor.hpp"
#include "StatusBarStyle.hpp"
#include "JStatusBarStyle.hpp"
#include "ModalPresentationStyle.hpp"
#include "JModalPresentationStyle.hpp"
#include "ModalTransitionStyle.hpp"
#include "JModalTransitionStyle.hpp"
#include "UserInterfaceStyle.hpp"
#include "JUserInterfaceStyle.hpp"
#include "FormSheetContentSize.hpp"
#include "JFormSheetContentSize.hpp"
#include "BrowserShareState.hpp"
#include "JBrowserShareState.hpp"
#include "BrowserColorScheme.hpp"
#include "JBrowserColorScheme.hpp"
#include <unordered_map>
#include "BrowserAnimations.hpp"
#include "JBrowserAnimations.hpp"

namespace margelo::nitro::inappbrowsernitro {

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

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

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

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

  // Properties
  

  // Methods
  std::shared_ptr<Promise<bool>> JHybridInappbrowserNitroSpec::isAvailable() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("isAvailable");
    auto __result = method(_javaPart);
    return [&]() {
      auto __promise = Promise<bool>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
        __promise->resolve(static_cast<bool>(__result->value()));
      });
      __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<InAppBrowserResult>> JHybridInappbrowserNitroSpec::open(const std::string& url, const std::optional<InAppBrowserOptions>& options) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<JInAppBrowserOptions> /* options */)>("open");
    auto __result = method(_javaPart, jni::make_jstring(url), options.has_value() ? JInAppBrowserOptions::fromCpp(options.value()) : nullptr);
    return [&]() {
      auto __promise = Promise<InAppBrowserResult>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JInAppBrowserResult>(__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<InAppBrowserAuthResult>> JHybridInappbrowserNitroSpec::openAuth(const std::string& url, const std::string& redirectUrl, const std::optional<InAppBrowserOptions>& options) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<jni::JString> /* redirectUrl */, jni::alias_ref<JInAppBrowserOptions> /* options */)>("openAuth");
    auto __result = method(_javaPart, jni::make_jstring(url), jni::make_jstring(redirectUrl), options.has_value() ? JInAppBrowserOptions::fromCpp(options.value()) : nullptr);
    return [&]() {
      auto __promise = Promise<InAppBrowserAuthResult>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JInAppBrowserAuthResult>(__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>> JHybridInappbrowserNitroSpec::close() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("close");
    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<void>> JHybridInappbrowserNitroSpec::closeAuth() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("closeAuth");
    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;
    }();
  }

} // namespace margelo::nitro::inappbrowsernitro
