///
/// JAudioRouteDescriptor.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 "AudioRouteDescriptor.hpp"

#include "JRoutePortType.hpp"
#include "RoutePortType.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::aviation {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct AudioRouteDescriptor by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    AudioRouteDescriptor toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldName = clazz->getField<jni::JString>("name");
      jni::local_ref<jni::JString> name = this->getFieldValue(fieldName);
      static const auto fieldPortType = clazz->getField<JRoutePortType>("portType");
      jni::local_ref<JRoutePortType> portType = this->getFieldValue(fieldPortType);
      return AudioRouteDescriptor(
        name != nullptr ? std::make_optional(name->toStdString()) : std::nullopt,
        portType->toCpp()
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JAudioRouteDescriptor::javaobject> fromCpp(const AudioRouteDescriptor& value) {
      using JSignature = JAudioRouteDescriptor(jni::alias_ref<jni::JString>, jni::alias_ref<JRoutePortType>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.name.has_value() ? jni::make_jstring(value.name.value()) : nullptr,
        JRoutePortType::fromCpp(value.portType)
      );
    }
  };

} // namespace margelo::nitro::aviation
