///
/// JLDP_NativeAssetSource.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 "LDP_NativeAssetSource.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::lunardatepicker {

  using namespace facebook;

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

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

} // namespace margelo::nitro::lunardatepicker
