///
/// JInAppBrowserAuthResult.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 "InAppBrowserAuthResult.hpp"

#include "BrowserResultType.hpp"
#include "JBrowserResultType.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::inappbrowsernitro {

  using namespace facebook;

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

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

} // namespace margelo::nitro::inappbrowsernitro
