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

#include "JHybridVideoPipelineSpec.hpp"

// Forward declaration of `VideoInfo` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct VideoInfo; }
// Forward declaration of `WGS84Coordinate` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct WGS84Coordinate; }
// Forward declaration of `EncoderCaps` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct EncoderCaps; }
// Forward declaration of `VideoCodec` to properly resolve imports.
namespace margelo::nitro::videopipeline { enum class VideoCodec; }
// Forward declaration of `ThumbnailOptions` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct ThumbnailOptions; }
// Forward declaration of `Size` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct Size; }
// Forward declaration of `BatchThumbnailOptions` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct BatchThumbnailOptions; }
// Forward declaration of `VideoSpec` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct VideoSpec; }
// Forward declaration of `OutputSpec` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct OutputSpec; }
// Forward declaration of `VideoContainer` to properly resolve imports.
namespace margelo::nitro::videopipeline { enum class VideoContainer; }
// Forward declaration of `ColorRange` to properly resolve imports.
namespace margelo::nitro::videopipeline { enum class ColorRange; }
// Forward declaration of `Clip` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct Clip; }
// Forward declaration of `ClipTransform` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct ClipTransform; }
// Forward declaration of `CropRect` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct CropRect; }
// Forward declaration of `TrackFrame` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct TrackFrame; }
// Forward declaration of `ImageOverlay` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct ImageOverlay; }
// Forward declaration of `TextOverlay` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct TextOverlay; }
// Forward declaration of `OverlayKind` to properly resolve imports.
namespace margelo::nitro::videopipeline { enum class OverlayKind; }
// Forward declaration of `AnchorPoint` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct AnchorPoint; }
// Forward declaration of `ImageOverlaySize` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct ImageOverlaySize; }
// Forward declaration of `Dim` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct Dim; }
// Forward declaration of `SizeUnit` to properly resolve imports.
namespace margelo::nitro::videopipeline { enum class SizeUnit; }
// Forward declaration of `TimeRange` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct TimeRange; }
// Forward declaration of `TextStyle` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct TextStyle; }
// Forward declaration of `FontWeight` to properly resolve imports.
namespace margelo::nitro::videopipeline { enum class FontWeight; }
// Forward declaration of `TextAlign` to properly resolve imports.
namespace margelo::nitro::videopipeline { enum class TextAlign; }
// Forward declaration of `TextShadow` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct TextShadow; }
// Forward declaration of `AudioSpec` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct AudioSpec; }
// Forward declaration of `AudioMode` to properly resolve imports.
namespace margelo::nitro::videopipeline { enum class AudioMode; }
// Forward declaration of `MetadataSpec` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct MetadataSpec; }
// Forward declaration of `FixedDuration` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct FixedDuration; }
// Forward declaration of `OpenDuration` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct OpenDuration; }
// Forward declaration of `DurationMode` to properly resolve imports.
namespace margelo::nitro::videopipeline { enum class DurationMode; }
// Forward declaration of `Progress` to properly resolve imports.
namespace margelo::nitro::videopipeline { struct Progress; }
// Forward declaration of `FlipAxis` to properly resolve imports.
namespace margelo::nitro::videopipeline { enum class FlipAxis; }
// Forward declaration of `HybridFrameTargetSpec` to properly resolve imports.
namespace margelo::nitro::videopipeline { class HybridFrameTargetSpec; }
// Forward declaration of `HybridFrameSourceSpec` to properly resolve imports.
namespace margelo::nitro::videopipeline { class HybridFrameSourceSpec; }

#include "VideoInfo.hpp"
#include <NitroModules/Promise.hpp>
#include <NitroModules/JPromise.hpp>
#include "JVideoInfo.hpp"
#include <string>
#include <chrono>
#include <optional>
#include <NitroModules/JInstant.hpp>
#include "WGS84Coordinate.hpp"
#include "JWGS84Coordinate.hpp"
#include <unordered_map>
#include <vector>
#include "EncoderCaps.hpp"
#include "JEncoderCaps.hpp"
#include "VideoCodec.hpp"
#include "JVideoCodec.hpp"
#include <NitroModules/JUnit.hpp>
#include "ThumbnailOptions.hpp"
#include "JThumbnailOptions.hpp"
#include "Size.hpp"
#include "JSize.hpp"
#include "BatchThumbnailOptions.hpp"
#include "JBatchThumbnailOptions.hpp"
#include "VideoSpec.hpp"
#include "JVideoSpec.hpp"
#include "OutputSpec.hpp"
#include "JOutputSpec.hpp"
#include "VideoContainer.hpp"
#include "JVideoContainer.hpp"
#include "ColorRange.hpp"
#include "JColorRange.hpp"
#include "Clip.hpp"
#include "JClip.hpp"
#include "ClipTransform.hpp"
#include "JClipTransform.hpp"
#include "CropRect.hpp"
#include "JCropRect.hpp"
#include "TrackFrame.hpp"
#include "JTrackFrame.hpp"
#include "ImageOverlay.hpp"
#include "TextOverlay.hpp"
#include <variant>
#include "JOverlay.hpp"
#include "JImageOverlay.hpp"
#include "OverlayKind.hpp"
#include "JOverlayKind.hpp"
#include "AnchorPoint.hpp"
#include "JAnchorPoint.hpp"
#include "ImageOverlaySize.hpp"
#include "JImageOverlaySize.hpp"
#include "Dim.hpp"
#include "JDim.hpp"
#include "SizeUnit.hpp"
#include "JSizeUnit.hpp"
#include "TimeRange.hpp"
#include "JTimeRange.hpp"
#include "JTextOverlay.hpp"
#include "TextStyle.hpp"
#include "JTextStyle.hpp"
#include "FontWeight.hpp"
#include "JFontWeight.hpp"
#include "TextAlign.hpp"
#include "JTextAlign.hpp"
#include "TextShadow.hpp"
#include "JTextShadow.hpp"
#include "AudioSpec.hpp"
#include "JAudioSpec.hpp"
#include "AudioMode.hpp"
#include "JAudioMode.hpp"
#include "MetadataSpec.hpp"
#include "JMetadataSpec.hpp"
#include "FixedDuration.hpp"
#include "OpenDuration.hpp"
#include "JVariant_FixedDuration_OpenDuration.hpp"
#include "JFixedDuration.hpp"
#include "DurationMode.hpp"
#include "JDurationMode.hpp"
#include "JOpenDuration.hpp"
#include "Progress.hpp"
#include <functional>
#include "JFunc_void_Progress.hpp"
#include <NitroModules/JNICallable.hpp>
#include "JProgress.hpp"
#include "FlipAxis.hpp"
#include "JFlipAxis.hpp"
#include "JVariant_ImageOverlay_TextOverlay.hpp"
#include <memory>
#include "HybridFrameTargetSpec.hpp"
#include "HybridFrameSourceSpec.hpp"
#include "JFunc_std__shared_ptr_Promise_bool___std__shared_ptr_HybridFrameTargetSpec__std__optional_std__shared_ptr_HybridFrameSourceSpec___double_double.hpp"
#include "JHybridFrameTargetSpec.hpp"
#include "JHybridFrameSourceSpec.hpp"

namespace margelo::nitro::videopipeline {

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

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

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

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

  // Properties
  

  // Methods
  std::shared_ptr<Promise<VideoInfo>> JHybridVideoPipelineSpec::info(const std::string& uri) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* uri */)>("info");
    auto __result = method(_javaPart, jni::make_jstring(uri));
    return [&]() {
      auto __promise = Promise<VideoInfo>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JVideoInfo>(__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<std::string>> JHybridVideoPipelineSpec::thumbnail(const std::string& uri, const ThumbnailOptions& options) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* uri */, jni::alias_ref<JThumbnailOptions> /* options */)>("thumbnail");
    auto __result = method(_javaPart, jni::make_jstring(uri), JThumbnailOptions::fromCpp(options));
    return [&]() {
      auto __promise = Promise<std::string>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<jni::JString>(__boxedResult);
        __promise->resolve(__result->toStdString());
      });
      __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<std::vector<std::string>>> JHybridVideoPipelineSpec::thumbnails(const std::string& uri, const BatchThumbnailOptions& options) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* uri */, jni::alias_ref<JBatchThumbnailOptions> /* options */)>("thumbnails");
    auto __result = method(_javaPart, jni::make_jstring(uri), JBatchThumbnailOptions::fromCpp(options));
    return [&]() {
      auto __promise = Promise<std::vector<std::string>>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<jni::JArrayClass<jni::JString>>(__boxedResult);
        __promise->resolve([&]() {
          size_t __size = __result->size();
          std::vector<std::string> __vector;
          __vector.reserve(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            auto __element = __result->getElement(__i);
            __vector.push_back(__element->toStdString());
          }
          return __vector;
        }());
      });
      __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<EncoderCaps>> JHybridVideoPipelineSpec::capabilities() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("capabilities");
    auto __result = method(_javaPart);
    return [&]() {
      auto __promise = Promise<EncoderCaps>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JEncoderCaps>(__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>> JHybridVideoPipelineSpec::render(const VideoSpec& spec, const std::string& renderToken, const std::optional<std::function<void(const Progress& /* p */)>>& onProgress) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JVideoSpec> /* spec */, jni::alias_ref<jni::JString> /* renderToken */, jni::alias_ref<JFunc_void_Progress::javaobject> /* onProgress */)>("render_cxx");
    auto __result = method(_javaPart, JVideoSpec::fromCpp(spec), jni::make_jstring(renderToken), onProgress.has_value() ? JFunc_void_Progress_cxx::fromCpp(onProgress.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;
    }();
  }
  void JHybridVideoPipelineSpec::cancelRender(const std::string& renderToken) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* renderToken */)>("cancelRender");
    method(_javaPart, jni::make_jstring(renderToken));
  }
  void JHybridVideoPipelineSpec::finishRender(const std::string& renderToken) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* renderToken */)>("finishRender");
    method(_javaPart, jni::make_jstring(renderToken));
  }
  std::shared_ptr<Promise<void>> JHybridVideoPipelineSpec::trim(const std::string& uri, const std::string& outPath, double startSec, double durationSec, const std::string& renderToken, const std::optional<std::function<void(const Progress& /* p */)>>& onProgress) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* uri */, jni::alias_ref<jni::JString> /* outPath */, double /* startSec */, double /* durationSec */, jni::alias_ref<jni::JString> /* renderToken */, jni::alias_ref<JFunc_void_Progress::javaobject> /* onProgress */)>("trim_cxx");
    auto __result = method(_javaPart, jni::make_jstring(uri), jni::make_jstring(outPath), startSec, durationSec, jni::make_jstring(renderToken), onProgress.has_value() ? JFunc_void_Progress_cxx::fromCpp(onProgress.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>> JHybridVideoPipelineSpec::flip(const std::string& uri, const std::string& outPath, FlipAxis axis, const std::string& renderToken, const std::optional<std::function<void(const Progress& /* p */)>>& onProgress) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* uri */, jni::alias_ref<jni::JString> /* outPath */, jni::alias_ref<JFlipAxis> /* axis */, jni::alias_ref<jni::JString> /* renderToken */, jni::alias_ref<JFunc_void_Progress::javaobject> /* onProgress */)>("flip_cxx");
    auto __result = method(_javaPart, jni::make_jstring(uri), jni::make_jstring(outPath), JFlipAxis::fromCpp(axis), jni::make_jstring(renderToken), onProgress.has_value() ? JFunc_void_Progress_cxx::fromCpp(onProgress.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>> JHybridVideoPipelineSpec::stamp(const std::string& uri, const std::string& outPath, const std::optional<std::variant<ImageOverlay, TextOverlay>>& watermark, const std::optional<MetadataSpec>& metadata, const std::string& renderToken, const std::optional<std::function<void(const Progress& /* p */)>>& onProgress) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* uri */, jni::alias_ref<jni::JString> /* outPath */, jni::alias_ref<JVariant_ImageOverlay_TextOverlay> /* watermark */, jni::alias_ref<JMetadataSpec> /* metadata */, jni::alias_ref<jni::JString> /* renderToken */, jni::alias_ref<JFunc_void_Progress::javaobject> /* onProgress */)>("stamp_cxx");
    auto __result = method(_javaPart, jni::make_jstring(uri), jni::make_jstring(outPath), watermark.has_value() ? JVariant_ImageOverlay_TextOverlay::fromCpp(watermark.value()) : nullptr, metadata.has_value() ? JMetadataSpec::fromCpp(metadata.value()) : nullptr, jni::make_jstring(renderToken), onProgress.has_value() ? JFunc_void_Progress_cxx::fromCpp(onProgress.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>> JHybridVideoPipelineSpec::renderCompose(const VideoSpec& spec, const std::string& renderToken, const std::function<std::shared_ptr<Promise<bool>>(const std::shared_ptr<HybridFrameTargetSpec>& /* target */, const std::optional<std::shared_ptr<HybridFrameSourceSpec>>& /* source */, double /* frameIndex */, double /* timeSec */)>& drawFrame, const std::optional<std::function<void(const Progress& /* p */)>>& onProgress) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JVideoSpec> /* spec */, jni::alias_ref<jni::JString> /* renderToken */, jni::alias_ref<JFunc_std__shared_ptr_Promise_bool___std__shared_ptr_HybridFrameTargetSpec__std__optional_std__shared_ptr_HybridFrameSourceSpec___double_double::javaobject> /* drawFrame */, jni::alias_ref<JFunc_void_Progress::javaobject> /* onProgress */)>("renderCompose_cxx");
    auto __result = method(_javaPart, JVideoSpec::fromCpp(spec), jni::make_jstring(renderToken), JFunc_std__shared_ptr_Promise_bool___std__shared_ptr_HybridFrameTargetSpec__std__optional_std__shared_ptr_HybridFrameSourceSpec___double_double_cxx::fromCpp(drawFrame), onProgress.has_value() ? JFunc_void_Progress_cxx::fromCpp(onProgress.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;
    }();
  }

} // namespace margelo::nitro::videopipeline
