///
/// JBandwidthData.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 "BandwidthData.hpp"

#include <optional>

namespace margelo::nitro::video {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct BandwidthData by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    BandwidthData toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldBitrate = clazz->getField<double>("bitrate");
      double bitrate = this->getFieldValue(fieldBitrate);
      static const auto fieldWidth = clazz->getField<jni::JDouble>("width");
      jni::local_ref<jni::JDouble> width = this->getFieldValue(fieldWidth);
      static const auto fieldHeight = clazz->getField<jni::JDouble>("height");
      jni::local_ref<jni::JDouble> height = this->getFieldValue(fieldHeight);
      return BandwidthData(
        bitrate,
        width != nullptr ? std::make_optional(width->value()) : std::nullopt,
        height != nullptr ? std::make_optional(height->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<JBandwidthData::javaobject> fromCpp(const BandwidthData& value) {
      return newInstance(
        value.bitrate,
        value.width.has_value() ? jni::JDouble::valueOf(value.width.value()) : nullptr,
        value.height.has_value() ? jni::JDouble::valueOf(value.height.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::video
