///
/// JRiveError.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 "RiveError.hpp"

#include "JRiveErrorType.hpp"
#include "RiveErrorType.hpp"
#include <string>

namespace margelo::nitro::rive {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct RiveError by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    RiveError toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldMessage = clazz->getField<jni::JString>("message");
      jni::local_ref<jni::JString> message = this->getFieldValue(fieldMessage);
      static const auto fieldType = clazz->getField<JRiveErrorType>("type");
      jni::local_ref<JRiveErrorType> type = this->getFieldValue(fieldType);
      return RiveError(
        message->toStdString(),
        type->toCpp()
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JRiveError::javaobject> fromCpp(const RiveError& value) {
      using JSignature = JRiveError(jni::alias_ref<jni::JString>, jni::alias_ref<JRiveErrorType>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.message),
        JRiveErrorType::fromCpp(value.type)
      );
    }
  };

} // namespace margelo::nitro::rive
