///
/// JReminderInput.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 "ReminderInput.hpp"

#include "CalendarRecurrence.hpp"
#include "CalendarRecurrenceFrequency.hpp"
#include "JCalendarRecurrence.hpp"
#include "JCalendarRecurrenceFrequency.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct ReminderInput by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    ReminderInput toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldTitle = clazz->getField<jni::JString>("title");
      jni::local_ref<jni::JString> title = this->getFieldValue(fieldTitle);
      static const auto fieldDueMs = clazz->getField<jni::JDouble>("dueMs");
      jni::local_ref<jni::JDouble> dueMs = this->getFieldValue(fieldDueMs);
      static const auto fieldRecurrence = clazz->getField<JCalendarRecurrence>("recurrence");
      jni::local_ref<JCalendarRecurrence> recurrence = this->getFieldValue(fieldRecurrence);
      return ReminderInput(
        title->toStdString(),
        dueMs != nullptr ? std::make_optional(dueMs->value()) : std::nullopt,
        recurrence != nullptr ? std::make_optional(recurrence->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<JReminderInput::javaobject> fromCpp(const ReminderInput& value) {
      using JSignature = JReminderInput(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JCalendarRecurrence>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.title),
        value.dueMs.has_value() ? jni::JDouble::valueOf(value.dueMs.value()) : nullptr,
        value.recurrence.has_value() ? JCalendarRecurrence::fromCpp(value.recurrence.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
