///
/// JKeyEventData.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once

#include <fbjni/fbjni.h>
#include "KeyEventData.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::keyevent {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct KeyEventData by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    KeyEventData toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldKeyCode = clazz->getField<double>("keyCode");
      double keyCode = this->getFieldValue(fieldKeyCode);
      static const auto fieldAction = clazz->getField<double>("action");
      double action = this->getFieldValue(fieldAction);
      static const auto fieldPressedKey = clazz->getField<jni::JString>("pressedKey");
      jni::local_ref<jni::JString> pressedKey = this->getFieldValue(fieldPressedKey);
      static const auto fieldRepeatCount = clazz->getField<jni::JDouble>("repeatCount");
      jni::local_ref<jni::JDouble> repeatCount = this->getFieldValue(fieldRepeatCount);
      return KeyEventData(
        keyCode,
        action,
        pressedKey->toStdString(),
        repeatCount != nullptr ? std::make_optional(repeatCount->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<JKeyEventData::javaobject> fromCpp(const KeyEventData& value) {
      return newInstance(
        value.keyCode,
        value.action,
        jni::make_jstring(value.pressedKey),
        value.repeatCount.has_value() ? jni::JDouble::valueOf(value.repeatCount.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::keyevent
