///
/// JLocationRegion.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 "LocationRegion.hpp"

#include "JRegionCenter.hpp"
#include "JRegionState.hpp"
#include "RegionCenter.hpp"
#include "RegionState.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct LocationRegion by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    LocationRegion toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldIdentifier = clazz->getField<jni::JString>("identifier");
      jni::local_ref<jni::JString> identifier = this->getFieldValue(fieldIdentifier);
      static const auto fieldCenter = clazz->getField<JRegionCenter>("center");
      jni::local_ref<JRegionCenter> center = this->getFieldValue(fieldCenter);
      static const auto fieldRadius = clazz->getField<double>("radius");
      double radius = this->getFieldValue(fieldRadius);
      static const auto fieldNotifyOnEntry = clazz->getField<jni::JBoolean>("notifyOnEntry");
      jni::local_ref<jni::JBoolean> notifyOnEntry = this->getFieldValue(fieldNotifyOnEntry);
      static const auto fieldNotifyOnExit = clazz->getField<jni::JBoolean>("notifyOnExit");
      jni::local_ref<jni::JBoolean> notifyOnExit = this->getFieldValue(fieldNotifyOnExit);
      static const auto fieldState = clazz->getField<JRegionState>("state");
      jni::local_ref<JRegionState> state = this->getFieldValue(fieldState);
      return LocationRegion(
        identifier->toStdString(),
        center->toCpp(),
        radius,
        notifyOnEntry != nullptr ? std::make_optional(static_cast<bool>(notifyOnEntry->value())) : std::nullopt,
        notifyOnExit != nullptr ? std::make_optional(static_cast<bool>(notifyOnExit->value())) : std::nullopt,
        state != nullptr ? std::make_optional(state->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<JLocationRegion::javaobject> fromCpp(const LocationRegion& value) {
      using JSignature = JLocationRegion(jni::alias_ref<jni::JString>, jni::alias_ref<JRegionCenter>, double, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JRegionState>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.identifier),
        JRegionCenter::fromCpp(value.center),
        value.radius,
        value.notifyOnEntry.has_value() ? jni::JBoolean::valueOf(value.notifyOnEntry.value()) : nullptr,
        value.notifyOnExit.has_value() ? jni::JBoolean::valueOf(value.notifyOnExit.value()) : nullptr,
        value.state.has_value() ? JRegionState::fromCpp(value.state.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
