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

#pragma once

#include <fbjni/fbjni.h>
#include "ImageOverlay.hpp"

#include "AnchorPoint.hpp"
#include "Dim.hpp"
#include "ImageOverlaySize.hpp"
#include "JAnchorPoint.hpp"
#include "JDim.hpp"
#include "JImageOverlaySize.hpp"
#include "JOverlayKind.hpp"
#include "JSizeUnit.hpp"
#include "JTimeRange.hpp"
#include "OverlayKind.hpp"
#include "SizeUnit.hpp"
#include "TimeRange.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::videopipeline {

  using namespace facebook;

  /**
   * The C++ JNI bridge between the C++ struct "ImageOverlay" and the the Kotlin data class "ImageOverlay".
   */
  struct JImageOverlay final: public jni::JavaClass<JImageOverlay> {
  public:
    static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/videopipeline/ImageOverlay;";

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct ImageOverlay by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    ImageOverlay toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldKind = clazz->getField<JOverlayKind>("kind");
      jni::local_ref<JOverlayKind> kind = this->getFieldValue(fieldKind);
      static const auto fieldUri = clazz->getField<jni::JString>("uri");
      jni::local_ref<jni::JString> uri = this->getFieldValue(fieldUri);
      static const auto fieldAnchor = clazz->getField<JAnchorPoint>("anchor");
      jni::local_ref<JAnchorPoint> anchor = this->getFieldValue(fieldAnchor);
      static const auto fieldSize = clazz->getField<JImageOverlaySize>("size");
      jni::local_ref<JImageOverlaySize> size = this->getFieldValue(fieldSize);
      static const auto fieldOpacity = clazz->getField<jni::JDouble>("opacity");
      jni::local_ref<jni::JDouble> opacity = this->getFieldValue(fieldOpacity);
      static const auto fieldTimeRange = clazz->getField<JTimeRange>("timeRange");
      jni::local_ref<JTimeRange> timeRange = this->getFieldValue(fieldTimeRange);
      return ImageOverlay(
        kind->toCpp(),
        uri->toStdString(),
        anchor->toCpp(),
        size->toCpp(),
        opacity != nullptr ? std::make_optional(opacity->value()) : std::nullopt,
        timeRange != nullptr ? std::make_optional(timeRange->toCpp()) : std::nullopt
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JImageOverlay::javaobject> fromCpp(const ImageOverlay& value) {
      using JSignature = JImageOverlay(jni::alias_ref<JOverlayKind>, jni::alias_ref<jni::JString>, jni::alias_ref<JAnchorPoint>, jni::alias_ref<JImageOverlaySize>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JTimeRange>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JOverlayKind::fromCpp(value.kind),
        jni::make_jstring(value.uri),
        JAnchorPoint::fromCpp(value.anchor),
        JImageOverlaySize::fromCpp(value.size),
        value.opacity.has_value() ? jni::JDouble::valueOf(value.opacity.value()) : nullptr,
        value.timeRange.has_value() ? JTimeRange::fromCpp(value.timeRange.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::videopipeline
