///
/// JAppleAuthResult.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 "AppleAuthResult.hpp"

#include "AppleAuthCredential.hpp"
#include "AppleAuthFullName.hpp"
#include "AppleAuthResultType.hpp"
#include "AppleRealUserStatus.hpp"
#include "JAppleAuthCredential.hpp"
#include "JAppleAuthFullName.hpp"
#include "JAppleAuthResultType.hpp"
#include "JAppleRealUserStatus.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

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

} // namespace margelo::nitro::one
