///
/// JEncoderCaps.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 "EncoderCaps.hpp"

#include "JVideoCodec.hpp"
#include "VideoCodec.hpp"
#include <vector>

namespace margelo::nitro::videopipeline {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct EncoderCaps by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    EncoderCaps toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldCodecs = clazz->getField<jni::JArrayClass<JVideoCodec>>("codecs");
      jni::local_ref<jni::JArrayClass<JVideoCodec>> codecs = this->getFieldValue(fieldCodecs);
      static const auto fieldMaxWidth = clazz->getField<double>("maxWidth");
      double maxWidth = this->getFieldValue(fieldMaxWidth);
      static const auto fieldMaxHeight = clazz->getField<double>("maxHeight");
      double maxHeight = this->getFieldValue(fieldMaxHeight);
      static const auto fieldMaxFps = clazz->getField<double>("maxFps");
      double maxFps = this->getFieldValue(fieldMaxFps);
      static const auto fieldMaxBitrate = clazz->getField<double>("maxBitrate");
      double maxBitrate = this->getFieldValue(fieldMaxBitrate);
      static const auto fieldHdr = clazz->getField<jboolean>("hdr");
      jboolean hdr = this->getFieldValue(fieldHdr);
      return EncoderCaps(
        [&]() {
          size_t __size = codecs->size();
          std::vector<VideoCodec> __vector;
          __vector.reserve(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            auto __element = codecs->getElement(__i);
            __vector.push_back(__element->toCpp());
          }
          return __vector;
        }(),
        maxWidth,
        maxHeight,
        maxFps,
        maxBitrate,
        static_cast<bool>(hdr)
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JEncoderCaps::javaobject> fromCpp(const EncoderCaps& value) {
      using JSignature = JEncoderCaps(jni::alias_ref<jni::JArrayClass<JVideoCodec>>, double, double, double, double, jboolean);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        [&]() {
          size_t __size = value.codecs.size();
          jni::local_ref<jni::JArrayClass<JVideoCodec>> __array = jni::JArrayClass<JVideoCodec>::newArray(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            const auto& __element = value.codecs[__i];
            auto __elementJni = JVideoCodec::fromCpp(__element);
            __array->setElement(__i, *__elementJni);
          }
          return __array;
        }(),
        value.maxWidth,
        value.maxHeight,
        value.maxFps,
        value.maxBitrate,
        value.hdr
      );
    }
  };

} // namespace margelo::nitro::videopipeline
