///
/// JCalendarEventInput.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 "CalendarEventInput.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 "CalendarEventInput" and the Kotlin data class "CalendarEventInput".
   */
  struct JCalendarEventInput final: public jni::JavaClass<JCalendarEventInput> {
  public:
    static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/one/CalendarEventInput;";

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct CalendarEventInput by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    CalendarEventInput 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 fieldStartMs = clazz->getField<double>("startMs");
      double startMs = this->getFieldValue(fieldStartMs);
      static const auto fieldEndMs = clazz->getField<double>("endMs");
      double endMs = this->getFieldValue(fieldEndMs);
      static const auto fieldAllDay = clazz->getField<jboolean>("allDay");
      jboolean allDay = this->getFieldValue(fieldAllDay);
      static const auto fieldRecurrence = clazz->getField<JCalendarRecurrence>("recurrence");
      jni::local_ref<JCalendarRecurrence> recurrence = this->getFieldValue(fieldRecurrence);
      return CalendarEventInput(
        title->toStdString(),
        startMs,
        endMs,
        static_cast<bool>(allDay),
        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<JCalendarEventInput::javaobject> fromCpp(const CalendarEventInput& value) {
      using JSignature = JCalendarEventInput(jni::alias_ref<jni::JString>, double, double, jboolean, 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.startMs,
        value.endMs,
        value.allDay,
        value.recurrence.has_value() ? JCalendarRecurrence::fromCpp(value.recurrence.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
