///
/// JCalendarInfo.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 "CalendarInfo.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct CalendarInfo by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    CalendarInfo toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldCalendar = clazz->getField<jni::JString>("calendar");
      jni::local_ref<jni::JString> calendar = this->getFieldValue(fieldCalendar);
      static const auto fieldTimeZone = clazz->getField<jni::JString>("timeZone");
      jni::local_ref<jni::JString> timeZone = this->getFieldValue(fieldTimeZone);
      static const auto fieldUses24hourClock = clazz->getField<jni::JBoolean>("uses24hourClock");
      jni::local_ref<jni::JBoolean> uses24hourClock = this->getFieldValue(fieldUses24hourClock);
      static const auto fieldFirstWeekday = clazz->getField<jni::JDouble>("firstWeekday");
      jni::local_ref<jni::JDouble> firstWeekday = this->getFieldValue(fieldFirstWeekday);
      return CalendarInfo(
        calendar != nullptr ? std::make_optional(calendar->toStdString()) : std::nullopt,
        timeZone != nullptr ? std::make_optional(timeZone->toStdString()) : std::nullopt,
        uses24hourClock != nullptr ? std::make_optional(static_cast<bool>(uses24hourClock->value())) : std::nullopt,
        firstWeekday != nullptr ? std::make_optional(firstWeekday->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<JCalendarInfo::javaobject> fromCpp(const CalendarInfo& value) {
      using JSignature = JCalendarInfo(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.calendar.has_value() ? jni::make_jstring(value.calendar.value()) : nullptr,
        value.timeZone.has_value() ? jni::make_jstring(value.timeZone.value()) : nullptr,
        value.uses24hourClock.has_value() ? jni::JBoolean::valueOf(value.uses24hourClock.value()) : nullptr,
        value.firstWeekday.has_value() ? jni::JDouble::valueOf(value.firstWeekday.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
