///
/// JPushErrorInfo.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 "PushErrorInfo.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::acousticconnectrn {

  using namespace facebook;

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

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

} // namespace margelo::nitro::acousticconnectrn
