///
/// JProgress.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 "Progress.hpp"

#include <optional>

namespace margelo::nitro::videopipeline {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct Progress by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    Progress toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldFramesCompleted = clazz->getField<double>("framesCompleted");
      double framesCompleted = this->getFieldValue(fieldFramesCompleted);
      static const auto fieldNbFrames = clazz->getField<jni::JDouble>("nbFrames");
      jni::local_ref<jni::JDouble> nbFrames = this->getFieldValue(fieldNbFrames);
      static const auto fieldElapsedMs = clazz->getField<double>("elapsedMs");
      double elapsedMs = this->getFieldValue(fieldElapsedMs);
      static const auto fieldEstimatedRemainingMs = clazz->getField<jni::JDouble>("estimatedRemainingMs");
      jni::local_ref<jni::JDouble> estimatedRemainingMs = this->getFieldValue(fieldEstimatedRemainingMs);
      return Progress(
        framesCompleted,
        nbFrames != nullptr ? std::make_optional(nbFrames->value()) : std::nullopt,
        elapsedMs,
        estimatedRemainingMs != nullptr ? std::make_optional(estimatedRemainingMs->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<JProgress::javaobject> fromCpp(const Progress& value) {
      using JSignature = JProgress(double, jni::alias_ref<jni::JDouble>, double, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.framesCompleted,
        value.nbFrames.has_value() ? jni::JDouble::valueOf(value.nbFrames.value()) : nullptr,
        value.elapsedMs,
        value.estimatedRemainingMs.has_value() ? jni::JDouble::valueOf(value.estimatedRemainingMs.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::videopipeline
