///
/// JImageResize.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 "ImageResize.hpp"

#include <optional>

namespace margelo::nitro::one {

  using namespace facebook;

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

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

} // namespace margelo::nitro::one
