///
/// JLocalAuthenticationStatus.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 "LocalAuthenticationStatus.hpp"

#include "JLocalBiometryType.hpp"
#include "LocalBiometryType.hpp"
#include <optional>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct LocalAuthenticationStatus by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    LocalAuthenticationStatus toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldAvailable = clazz->getField<jboolean>("available");
      jboolean available = this->getFieldValue(fieldAvailable);
      static const auto fieldBiometryType = clazz->getField<JLocalBiometryType>("biometryType");
      jni::local_ref<JLocalBiometryType> biometryType = this->getFieldValue(fieldBiometryType);
      static const auto fieldErrorCode = clazz->getField<jni::JDouble>("errorCode");
      jni::local_ref<jni::JDouble> errorCode = this->getFieldValue(fieldErrorCode);
      return LocalAuthenticationStatus(
        static_cast<bool>(available),
        biometryType->toCpp(),
        errorCode != nullptr ? std::make_optional(errorCode->value()) : 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<JLocalAuthenticationStatus::javaobject> fromCpp(const LocalAuthenticationStatus& value) {
      using JSignature = JLocalAuthenticationStatus(jboolean, jni::alias_ref<JLocalBiometryType>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.available,
        JLocalBiometryType::fromCpp(value.biometryType),
        value.errorCode.has_value() ? jni::JDouble::valueOf(value.errorCode.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
