///
/// JSize.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 "Size.hpp"

#include <optional>

namespace margelo::nitro::videopipeline {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct Size by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    Size toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldW = clazz->getField<jni::JDouble>("w");
      jni::local_ref<jni::JDouble> w = this->getFieldValue(fieldW);
      static const auto fieldH = clazz->getField<jni::JDouble>("h");
      jni::local_ref<jni::JDouble> h = this->getFieldValue(fieldH);
      return Size(
        w != nullptr ? std::make_optional(w->value()) : std::nullopt,
        h != nullptr ? std::make_optional(h->value()) : 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<JSize::javaobject> fromCpp(const Size& value) {
      using JSignature = JSize(jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.w.has_value() ? jni::JDouble::valueOf(value.w.value()) : nullptr,
        value.h.has_value() ? jni::JDouble::valueOf(value.h.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::videopipeline
