///
/// JLivePlaybackParams.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 "LivePlaybackParams.hpp"

#include <optional>

namespace margelo::nitro::video {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct LivePlaybackParams by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    LivePlaybackParams toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldMinPlaybackSpeed = clazz->getField<jni::JDouble>("minPlaybackSpeed");
      jni::local_ref<jni::JDouble> minPlaybackSpeed = this->getFieldValue(fieldMinPlaybackSpeed);
      static const auto fieldMaxPlaybackSpeed = clazz->getField<jni::JDouble>("maxPlaybackSpeed");
      jni::local_ref<jni::JDouble> maxPlaybackSpeed = this->getFieldValue(fieldMaxPlaybackSpeed);
      static const auto fieldMaxOffsetMs = clazz->getField<jni::JDouble>("maxOffsetMs");
      jni::local_ref<jni::JDouble> maxOffsetMs = this->getFieldValue(fieldMaxOffsetMs);
      static const auto fieldMinOffsetMs = clazz->getField<jni::JDouble>("minOffsetMs");
      jni::local_ref<jni::JDouble> minOffsetMs = this->getFieldValue(fieldMinOffsetMs);
      static const auto fieldTargetOffsetMs = clazz->getField<jni::JDouble>("targetOffsetMs");
      jni::local_ref<jni::JDouble> targetOffsetMs = this->getFieldValue(fieldTargetOffsetMs);
      return LivePlaybackParams(
        minPlaybackSpeed != nullptr ? std::make_optional(minPlaybackSpeed->value()) : std::nullopt,
        maxPlaybackSpeed != nullptr ? std::make_optional(maxPlaybackSpeed->value()) : std::nullopt,
        maxOffsetMs != nullptr ? std::make_optional(maxOffsetMs->value()) : std::nullopt,
        minOffsetMs != nullptr ? std::make_optional(minOffsetMs->value()) : std::nullopt,
        targetOffsetMs != nullptr ? std::make_optional(targetOffsetMs->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<JLivePlaybackParams::javaobject> fromCpp(const LivePlaybackParams& value) {
      return newInstance(
        value.minPlaybackSpeed.has_value() ? jni::JDouble::valueOf(value.minPlaybackSpeed.value()) : nullptr,
        value.maxPlaybackSpeed.has_value() ? jni::JDouble::valueOf(value.maxPlaybackSpeed.value()) : nullptr,
        value.maxOffsetMs.has_value() ? jni::JDouble::valueOf(value.maxOffsetMs.value()) : nullptr,
        value.minOffsetMs.has_value() ? jni::JDouble::valueOf(value.minOffsetMs.value()) : nullptr,
        value.targetOffsetMs.has_value() ? jni::JDouble::valueOf(value.targetOffsetMs.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::video
