///
/// JLocationPlace.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 "LocationPlace.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct LocationPlace by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    LocationPlace toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldLatitude = clazz->getField<double>("latitude");
      double latitude = this->getFieldValue(fieldLatitude);
      static const auto fieldLongitude = clazz->getField<double>("longitude");
      double longitude = this->getFieldValue(fieldLongitude);
      static const auto fieldName = clazz->getField<jni::JString>("name");
      jni::local_ref<jni::JString> name = this->getFieldValue(fieldName);
      static const auto fieldStreet = clazz->getField<jni::JString>("street");
      jni::local_ref<jni::JString> street = this->getFieldValue(fieldStreet);
      static const auto fieldHouseNumber = clazz->getField<jni::JString>("houseNumber");
      jni::local_ref<jni::JString> houseNumber = this->getFieldValue(fieldHouseNumber);
      static const auto fieldCity = clazz->getField<jni::JString>("city");
      jni::local_ref<jni::JString> city = this->getFieldValue(fieldCity);
      static const auto fieldRegion = clazz->getField<jni::JString>("region");
      jni::local_ref<jni::JString> region = this->getFieldValue(fieldRegion);
      static const auto fieldPostalCode = clazz->getField<jni::JString>("postalCode");
      jni::local_ref<jni::JString> postalCode = this->getFieldValue(fieldPostalCode);
      static const auto fieldCountry = clazz->getField<jni::JString>("country");
      jni::local_ref<jni::JString> country = this->getFieldValue(fieldCountry);
      static const auto fieldIsoCountryCode = clazz->getField<jni::JString>("isoCountryCode");
      jni::local_ref<jni::JString> isoCountryCode = this->getFieldValue(fieldIsoCountryCode);
      return LocationPlace(
        latitude,
        longitude,
        name != nullptr ? std::make_optional(name->toStdString()) : std::nullopt,
        street != nullptr ? std::make_optional(street->toStdString()) : std::nullopt,
        houseNumber != nullptr ? std::make_optional(houseNumber->toStdString()) : std::nullopt,
        city != nullptr ? std::make_optional(city->toStdString()) : std::nullopt,
        region != nullptr ? std::make_optional(region->toStdString()) : std::nullopt,
        postalCode != nullptr ? std::make_optional(postalCode->toStdString()) : std::nullopt,
        country != nullptr ? std::make_optional(country->toStdString()) : std::nullopt,
        isoCountryCode != nullptr ? std::make_optional(isoCountryCode->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<JLocationPlace::javaobject> fromCpp(const LocationPlace& value) {
      using JSignature = JLocationPlace(double, double, 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<jni::JString>, 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.latitude,
        value.longitude,
        value.name.has_value() ? jni::make_jstring(value.name.value()) : nullptr,
        value.street.has_value() ? jni::make_jstring(value.street.value()) : nullptr,
        value.houseNumber.has_value() ? jni::make_jstring(value.houseNumber.value()) : nullptr,
        value.city.has_value() ? jni::make_jstring(value.city.value()) : nullptr,
        value.region.has_value() ? jni::make_jstring(value.region.value()) : nullptr,
        value.postalCode.has_value() ? jni::make_jstring(value.postalCode.value()) : nullptr,
        value.country.has_value() ? jni::make_jstring(value.country.value()) : nullptr,
        value.isoCountryCode.has_value() ? jni::make_jstring(value.isoCountryCode.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
