///
/// JAppleAuthSignInOptions.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 "AppleAuthSignInOptions.hpp"

#include "AppleAuthScope.hpp"
#include "JAppleAuthScope.hpp"
#include <optional>
#include <string>
#include <vector>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct AppleAuthSignInOptions by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    AppleAuthSignInOptions toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldRequestedScopes = clazz->getField<jni::JArrayClass<JAppleAuthScope>>("requestedScopes");
      jni::local_ref<jni::JArrayClass<JAppleAuthScope>> requestedScopes = this->getFieldValue(fieldRequestedScopes);
      static const auto fieldNonce = clazz->getField<jni::JString>("nonce");
      jni::local_ref<jni::JString> nonce = this->getFieldValue(fieldNonce);
      static const auto fieldState = clazz->getField<jni::JString>("state");
      jni::local_ref<jni::JString> state = this->getFieldValue(fieldState);
      return AppleAuthSignInOptions(
        requestedScopes != nullptr ? std::make_optional([&](auto&& __input) {
          size_t __size = __input->size();
          std::vector<AppleAuthScope> __vector;
          __vector.reserve(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            auto __element = __input->getElement(__i);
            __vector.push_back(__element->toCpp());
          }
          return __vector;
        }(requestedScopes)) : std::nullopt,
        nonce != nullptr ? std::make_optional(nonce->toStdString()) : std::nullopt,
        state != nullptr ? std::make_optional(state->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<JAppleAuthSignInOptions::javaobject> fromCpp(const AppleAuthSignInOptions& value) {
      using JSignature = JAppleAuthSignInOptions(jni::alias_ref<jni::JArrayClass<JAppleAuthScope>>, 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.requestedScopes.has_value() ? [&](auto&& __input) {
          size_t __size = __input.size();
          jni::local_ref<jni::JArrayClass<JAppleAuthScope>> __array = jni::JArrayClass<JAppleAuthScope>::newArray(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            const auto& __element = __input[__i];
            auto __elementJni = JAppleAuthScope::fromCpp(__element);
            __array->setElement(__i, *__elementJni);
          }
          return __array;
        }(value.requestedScopes.value()) : nullptr,
        value.nonce.has_value() ? jni::make_jstring(value.nonce.value()) : nullptr,
        value.state.has_value() ? jni::make_jstring(value.state.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
