///
/// JArtboardBy.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 "ArtboardBy.hpp"

#include "ArtboardByTypes.hpp"
#include "JArtboardByTypes.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::rive {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct ArtboardBy by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    ArtboardBy toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldType = clazz->getField<JArtboardByTypes>("type");
      jni::local_ref<JArtboardByTypes> type = this->getFieldValue(fieldType);
      static const auto fieldIndex = clazz->getField<jni::JDouble>("index");
      jni::local_ref<jni::JDouble> index = this->getFieldValue(fieldIndex);
      static const auto fieldName = clazz->getField<jni::JString>("name");
      jni::local_ref<jni::JString> name = this->getFieldValue(fieldName);
      return ArtboardBy(
        type->toCpp(),
        index != nullptr ? std::make_optional(index->value()) : std::nullopt,
        name != nullptr ? std::make_optional(name->toStdString()) : 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<JArtboardBy::javaobject> fromCpp(const ArtboardBy& value) {
      using JSignature = JArtboardBy(jni::alias_ref<JArtboardByTypes>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JString>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JArtboardByTypes::fromCpp(value.type),
        value.index.has_value() ? jni::JDouble::valueOf(value.index.value()) : nullptr,
        value.name.has_value() ? jni::make_jstring(value.name.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::rive
