///
/// JL2CAPChannel.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 "L2CAPChannel.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::munimbluetooth {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct L2CAPChannel by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    L2CAPChannel toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldId = clazz->getField<jni::JString>("id");
      jni::local_ref<jni::JString> id = this->getFieldValue(fieldId);
      static const auto fieldPsm = clazz->getField<double>("psm");
      double psm = this->getFieldValue(fieldPsm);
      static const auto fieldDeviceId = clazz->getField<jni::JString>("deviceId");
      jni::local_ref<jni::JString> deviceId = this->getFieldValue(fieldDeviceId);
      return L2CAPChannel(
        id->toStdString(),
        psm,
        deviceId != nullptr ? std::make_optional(deviceId->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<JL2CAPChannel::javaobject> fromCpp(const L2CAPChannel& value) {
      using JSignature = JL2CAPChannel(jni::alias_ref<jni::JString>, double, jni::alias_ref<jni::JString>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.id),
        value.psm,
        value.deviceId.has_value() ? jni::make_jstring(value.deviceId.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::munimbluetooth
