///
/// JBrowserAuthResult.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 "BrowserAuthResult.hpp"

#include "BrowserAuthResultType.hpp"
#include "JBrowserAuthResultType.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

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

} // namespace margelo::nitro::one
