///
/// JAppleAuthCredential.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 "AppleAuthCredential.hpp"

#include "AppleAuthFullName.hpp"
#include "AppleRealUserStatus.hpp"
#include "JAppleAuthFullName.hpp"
#include "JAppleRealUserStatus.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct AppleAuthCredential by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    AppleAuthCredential toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldUser = clazz->getField<jni::JString>("user");
      jni::local_ref<jni::JString> user = this->getFieldValue(fieldUser);
      static const auto fieldState = clazz->getField<jni::JString>("state");
      jni::local_ref<jni::JString> state = this->getFieldValue(fieldState);
      static const auto fieldIdentityToken = clazz->getField<jni::JString>("identityToken");
      jni::local_ref<jni::JString> identityToken = this->getFieldValue(fieldIdentityToken);
      static const auto fieldAuthorizationCode = clazz->getField<jni::JString>("authorizationCode");
      jni::local_ref<jni::JString> authorizationCode = this->getFieldValue(fieldAuthorizationCode);
      static const auto fieldEmail = clazz->getField<jni::JString>("email");
      jni::local_ref<jni::JString> email = this->getFieldValue(fieldEmail);
      static const auto fieldFullName = clazz->getField<JAppleAuthFullName>("fullName");
      jni::local_ref<JAppleAuthFullName> fullName = this->getFieldValue(fieldFullName);
      static const auto fieldRealUserStatus = clazz->getField<JAppleRealUserStatus>("realUserStatus");
      jni::local_ref<JAppleRealUserStatus> realUserStatus = this->getFieldValue(fieldRealUserStatus);
      return AppleAuthCredential(
        user->toStdString(),
        state != nullptr ? std::make_optional(state->toStdString()) : std::nullopt,
        identityToken != nullptr ? std::make_optional(identityToken->toStdString()) : std::nullopt,
        authorizationCode != nullptr ? std::make_optional(authorizationCode->toStdString()) : std::nullopt,
        email != nullptr ? std::make_optional(email->toStdString()) : std::nullopt,
        fullName != nullptr ? std::make_optional(fullName->toCpp()) : std::nullopt,
        realUserStatus->toCpp()
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JAppleAuthCredential::javaobject> fromCpp(const AppleAuthCredential& value) {
      using JSignature = JAppleAuthCredential(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<JAppleAuthFullName>, jni::alias_ref<JAppleRealUserStatus>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.user),
        value.state.has_value() ? jni::make_jstring(value.state.value()) : nullptr,
        value.identityToken.has_value() ? jni::make_jstring(value.identityToken.value()) : nullptr,
        value.authorizationCode.has_value() ? jni::make_jstring(value.authorizationCode.value()) : nullptr,
        value.email.has_value() ? jni::make_jstring(value.email.value()) : nullptr,
        value.fullName.has_value() ? JAppleAuthFullName::fromCpp(value.fullName.value()) : nullptr,
        JAppleRealUserStatus::fromCpp(value.realUserStatus)
      );
    }
  };

} // namespace margelo::nitro::one
