///
/// JCustomError.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 "CustomError.hpp"

#include "ErrorCode.hpp"
#include "JErrorCode.hpp"
#include <string>

namespace margelo::nitro::taponpagseguro {

  using namespace facebook;

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

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

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

} // namespace margelo::nitro::taponpagseguro
