///
/// JPlaybackMetricEvent.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 "PlaybackMetricEvent.hpp"

#include "JPlaybackMetricType.hpp"
#include "JTtffSource.hpp"
#include "PlaybackMetricType.hpp"
#include "TtffSource.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::aviation {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct PlaybackMetricEvent by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    PlaybackMetricEvent toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldType = clazz->getField<JPlaybackMetricType>("type");
      jni::local_ref<JPlaybackMetricType> type = this->getFieldValue(fieldType);
      static const auto fieldUri = clazz->getField<jni::JString>("uri");
      jni::local_ref<jni::JString> uri = this->getFieldValue(fieldUri);
      static const auto fieldBytes = clazz->getField<jni::JDouble>("bytes");
      jni::local_ref<jni::JDouble> bytes = this->getFieldValue(fieldBytes);
      static const auto fieldLayer = clazz->getField<jni::JDouble>("layer");
      jni::local_ref<jni::JDouble> layer = this->getFieldValue(fieldLayer);
      static const auto fieldDurationMs = clazz->getField<jni::JDouble>("durationMs");
      jni::local_ref<jni::JDouble> durationMs = this->getFieldValue(fieldDurationMs);
      static const auto fieldSource = clazz->getField<JTtffSource>("source");
      jni::local_ref<JTtffSource> source = this->getFieldValue(fieldSource);
      static const auto fieldError = clazz->getField<jni::JString>("error");
      jni::local_ref<jni::JString> error = this->getFieldValue(fieldError);
      return PlaybackMetricEvent(
        type->toCpp(),
        uri != nullptr ? std::make_optional(uri->toStdString()) : std::nullopt,
        bytes != nullptr ? std::make_optional(bytes->value()) : std::nullopt,
        layer != nullptr ? std::make_optional(layer->value()) : std::nullopt,
        durationMs != nullptr ? std::make_optional(durationMs->value()) : std::nullopt,
        source != nullptr ? std::make_optional(source->toCpp()) : std::nullopt,
        error != nullptr ? std::make_optional(error->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<JPlaybackMetricEvent::javaobject> fromCpp(const PlaybackMetricEvent& value) {
      using JSignature = JPlaybackMetricEvent(jni::alias_ref<JPlaybackMetricType>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JTtffSource>, jni::alias_ref<jni::JString>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JPlaybackMetricType::fromCpp(value.type),
        value.uri.has_value() ? jni::make_jstring(value.uri.value()) : nullptr,
        value.bytes.has_value() ? jni::JDouble::valueOf(value.bytes.value()) : nullptr,
        value.layer.has_value() ? jni::JDouble::valueOf(value.layer.value()) : nullptr,
        value.durationMs.has_value() ? jni::JDouble::valueOf(value.durationMs.value()) : nullptr,
        value.source.has_value() ? JTtffSource::fromCpp(value.source.value()) : nullptr,
        value.error.has_value() ? jni::make_jstring(value.error.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::aviation
