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

#include "JHybridAdsControllerSpec.hpp"

// Forward declaration of `AdBreakInfo` to properly resolve imports.
namespace margelo::nitro::aviation { struct AdBreakInfo; }
// Forward declaration of `AdInfo` to properly resolve imports.
namespace margelo::nitro::aviation { struct AdInfo; }
// Forward declaration of `AdsConfig` to properly resolve imports.
namespace margelo::nitro::aviation { struct AdsConfig; }
// Forward declaration of `CuePoint` to properly resolve imports.
namespace margelo::nitro::aviation { struct CuePoint; }

#include "AdBreakInfo.hpp"
#include <optional>
#include "JAdBreakInfo.hpp"
#include "AdInfo.hpp"
#include "JAdInfo.hpp"
#include <string>
#include <NitroModules/Promise.hpp>
#include <NitroModules/JPromise.hpp>
#include <NitroModules/JUnit.hpp>
#include "AdsConfig.hpp"
#include "JAdsConfig.hpp"
#include "CuePoint.hpp"
#include <vector>
#include "JCuePoint.hpp"
#include <functional>
#include "JFunc_void_AdBreakInfo.hpp"
#include <NitroModules/JNICallable.hpp>
#include "JFunc_void_AdInfo.hpp"
#include "JFunc_void_std__string.hpp"
#include "JFunc_void.hpp"

namespace margelo::nitro::aviation {

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

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

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

  bool JHybridAdsControllerSpec::equals(const std::shared_ptr<HybridObject>& other) {
    if (auto otherCast = std::dynamic_pointer_cast<JHybridAdsControllerSpec>(other)) {
      return _javaPart == otherCast->_javaPart;
    }
    return false;
  }

  void JHybridAdsControllerSpec::dispose() noexcept {
    static const auto method = javaClassStatic()->getMethod<void()>("dispose");
    method(_javaPart);
  }

  std::string JHybridAdsControllerSpec::toString() {
    static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
    auto javaString = method(_javaPart);
    return javaString->toStdString();
  }

  // Properties
  bool JHybridAdsControllerSpec::getIsPlayingAd() {
    static const auto method = javaClassStatic()->getMethod<jboolean()>("isPlayingAd");
    auto __result = method(_javaPart);
    return static_cast<bool>(__result);
  }
  std::optional<AdBreakInfo> JHybridAdsControllerSpec::getCurrentAdBreakInfo() {
    static const auto method = javaClassStatic()->getMethod<jni::local_ref<JAdBreakInfo>()>("getCurrentAdBreakInfo");
    auto __result = method(_javaPart);
    return __result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt;
  }
  std::optional<AdInfo> JHybridAdsControllerSpec::getCurrentAdInfo() {
    static const auto method = javaClassStatic()->getMethod<jni::local_ref<JAdInfo>()>("getCurrentAdInfo");
    auto __result = method(_javaPart);
    return __result != nullptr ? std::make_optional(__result->toCpp()) : std::nullopt;
  }

  // Methods
  void JHybridAdsControllerSpec::configure(const AdsConfig& config) {
    static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JAdsConfig> /* config */)>("configure");
    method(_javaPart, JAdsConfig::fromCpp(config));
  }
  void JHybridAdsControllerSpec::setAdTagUrl(const std::string& url) {
    static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* url */)>("setAdTagUrl");
    method(_javaPart, jni::make_jstring(url));
  }
  void JHybridAdsControllerSpec::addCuePoint(double timeMs, const std::string& adTagUrl) {
    static const auto method = javaClassStatic()->getMethod<void(double /* timeMs */, jni::alias_ref<jni::JString> /* adTagUrl */)>("addCuePoint");
    method(_javaPart, timeMs, jni::make_jstring(adTagUrl));
  }
  void JHybridAdsControllerSpec::removeCuePoint(double timeMs) {
    static const auto method = javaClassStatic()->getMethod<void(double /* timeMs */)>("removeCuePoint");
    method(_javaPart, timeMs);
  }
  void JHybridAdsControllerSpec::clearCuePoints() {
    static const auto method = javaClassStatic()->getMethod<void()>("clearCuePoints");
    method(_javaPart);
  }
  std::shared_ptr<Promise<void>> JHybridAdsControllerSpec::requestAd(const std::string& adTagUrl) {
    static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* adTagUrl */)>("requestAd");
    auto __result = method(_javaPart, jni::make_jstring(adTagUrl));
    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;
    }();
  }
  void JHybridAdsControllerSpec::skipAd() {
    static const auto method = javaClassStatic()->getMethod<void()>("skipAd");
    method(_javaPart);
  }
  void JHybridAdsControllerSpec::pauseAd() {
    static const auto method = javaClassStatic()->getMethod<void()>("pauseAd");
    method(_javaPart);
  }
  void JHybridAdsControllerSpec::resumeAd() {
    static const auto method = javaClassStatic()->getMethod<void()>("resumeAd");
    method(_javaPart);
  }
  void JHybridAdsControllerSpec::onAdBreakStarted(const std::function<void(const AdBreakInfo& /* info */)>& callback) {
    static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_AdBreakInfo::javaobject> /* callback */)>("onAdBreakStarted_cxx");
    method(_javaPart, JFunc_void_AdBreakInfo_cxx::fromCpp(callback));
  }
  void JHybridAdsControllerSpec::onAdBreakEnded(const std::function<void(const AdBreakInfo& /* info */)>& callback) {
    static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_AdBreakInfo::javaobject> /* callback */)>("onAdBreakEnded_cxx");
    method(_javaPart, JFunc_void_AdBreakInfo_cxx::fromCpp(callback));
  }
  void JHybridAdsControllerSpec::onAdStarted(const std::function<void(const AdInfo& /* info */)>& callback) {
    static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_AdInfo::javaobject> /* callback */)>("onAdStarted_cxx");
    method(_javaPart, JFunc_void_AdInfo_cxx::fromCpp(callback));
  }
  void JHybridAdsControllerSpec::onAdCompleted(const std::function<void(const AdInfo& /* info */)>& callback) {
    static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_AdInfo::javaobject> /* callback */)>("onAdCompleted_cxx");
    method(_javaPart, JFunc_void_AdInfo_cxx::fromCpp(callback));
  }
  void JHybridAdsControllerSpec::onAdProgress(const std::function<void(const AdInfo& /* info */)>& callback) {
    static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_AdInfo::javaobject> /* callback */)>("onAdProgress_cxx");
    method(_javaPart, JFunc_void_AdInfo_cxx::fromCpp(callback));
  }
  void JHybridAdsControllerSpec::onAdSkipped(const std::function<void(const AdInfo& /* info */)>& callback) {
    static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_AdInfo::javaobject> /* callback */)>("onAdSkipped_cxx");
    method(_javaPart, JFunc_void_AdInfo_cxx::fromCpp(callback));
  }
  void JHybridAdsControllerSpec::onAdTapped(const std::function<void(const AdInfo& /* info */)>& callback) {
    static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_AdInfo::javaobject> /* callback */)>("onAdTapped_cxx");
    method(_javaPart, JFunc_void_AdInfo_cxx::fromCpp(callback));
  }
  void JHybridAdsControllerSpec::onAdError(const std::function<void(const std::string& /* error */)>& callback) {
    static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_std__string::javaobject> /* callback */)>("onAdError_cxx");
    method(_javaPart, JFunc_void_std__string_cxx::fromCpp(callback));
  }
  void JHybridAdsControllerSpec::onAllAdsCompleted(const std::function<void()>& callback) {
    static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void::javaobject> /* callback */)>("onAllAdsCompleted_cxx");
    method(_javaPart, JFunc_void_cxx::fromCpp(callback));
  }
  void JHybridAdsControllerSpec::release() {
    static const auto method = javaClassStatic()->getMethod<void()>("release");
    method(_javaPart);
  }

} // namespace margelo::nitro::aviation
