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

#include "JHybridNitroInAppBrowserSpec.hpp"

// Forward declaration of `NitroInAppBrowserOptions` to properly resolve imports.
namespace margelo::nitro::nitroinappbrowser { struct NitroInAppBrowserOptions; }
// Forward declaration of `NitroInAppBrowserDismissButtonLabel` to properly resolve imports.
namespace margelo::nitro::nitroinappbrowser { enum class NitroInAppBrowserDismissButtonLabel; }
// Forward declaration of `NitroInAppBrowserPresentationStyle` to properly resolve imports.
namespace margelo::nitro::nitroinappbrowser { enum class NitroInAppBrowserPresentationStyle; }

#include <NitroModules/Promise.hpp>
#include <NitroModules/JPromise.hpp>
#include <NitroModules/JUnit.hpp>
#include <string>
#include "NitroInAppBrowserOptions.hpp"
#include <optional>
#include "JNitroInAppBrowserOptions.hpp"
#include "NitroInAppBrowserDismissButtonLabel.hpp"
#include "JNitroInAppBrowserDismissButtonLabel.hpp"
#include "NitroInAppBrowserPresentationStyle.hpp"
#include "JNitroInAppBrowserPresentationStyle.hpp"

namespace margelo::nitro::nitroinappbrowser {

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

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

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

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

  // Properties
  

  // Methods
  std::shared_ptr<Promise<void>> JHybridNitroInAppBrowserSpec::open(const std::string& url, const std::optional<NitroInAppBrowserOptions>& options) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<JNitroInAppBrowserOptions> /* options */)>("open");
    auto __result = method(_javaPart, jni::make_jstring(url), options.has_value() ? JNitroInAppBrowserOptions::fromCpp(options.value()) : nullptr);
    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>> JHybridNitroInAppBrowserSpec::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;
    }();
  }

} // namespace margelo::nitro::nitroinappbrowser
