///
/// JVideoOutputOptions.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 "VideoOutputOptions.hpp"

#include "JRecorderFileType.hpp"
#include "JSize.hpp"
#include "RecorderFileType.hpp"
#include "Size.hpp"
#include <optional>

namespace margelo::nitro::camera {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct VideoOutputOptions by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    VideoOutputOptions toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldTargetResolution = clazz->getField<JSize>("targetResolution");
      jni::local_ref<JSize> targetResolution = this->getFieldValue(fieldTargetResolution);
      static const auto fieldEnableAudio = clazz->getField<jni::JBoolean>("enableAudio");
      jni::local_ref<jni::JBoolean> enableAudio = this->getFieldValue(fieldEnableAudio);
      static const auto fieldEnablePersistentRecorder = clazz->getField<jni::JBoolean>("enablePersistentRecorder");
      jni::local_ref<jni::JBoolean> enablePersistentRecorder = this->getFieldValue(fieldEnablePersistentRecorder);
      static const auto fieldEnableHigherResolutionCodecs = clazz->getField<jni::JBoolean>("enableHigherResolutionCodecs");
      jni::local_ref<jni::JBoolean> enableHigherResolutionCodecs = this->getFieldValue(fieldEnableHigherResolutionCodecs);
      static const auto fieldTargetBitRate = clazz->getField<jni::JDouble>("targetBitRate");
      jni::local_ref<jni::JDouble> targetBitRate = this->getFieldValue(fieldTargetBitRate);
      static const auto fieldFileType = clazz->getField<JRecorderFileType>("fileType");
      jni::local_ref<JRecorderFileType> fileType = this->getFieldValue(fieldFileType);
      return VideoOutputOptions(
        targetResolution->toCpp(),
        enableAudio != nullptr ? std::make_optional(static_cast<bool>(enableAudio->value())) : std::nullopt,
        enablePersistentRecorder != nullptr ? std::make_optional(static_cast<bool>(enablePersistentRecorder->value())) : std::nullopt,
        enableHigherResolutionCodecs != nullptr ? std::make_optional(static_cast<bool>(enableHigherResolutionCodecs->value())) : std::nullopt,
        targetBitRate != nullptr ? std::make_optional(targetBitRate->value()) : std::nullopt,
        fileType != nullptr ? std::make_optional(fileType->toCpp()) : 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<JVideoOutputOptions::javaobject> fromCpp(const VideoOutputOptions& value) {
      using JSignature = JVideoOutputOptions(jni::alias_ref<JSize>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JRecorderFileType>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JSize::fromCpp(value.targetResolution),
        value.enableAudio.has_value() ? jni::JBoolean::valueOf(value.enableAudio.value()) : nullptr,
        value.enablePersistentRecorder.has_value() ? jni::JBoolean::valueOf(value.enablePersistentRecorder.value()) : nullptr,
        value.enableHigherResolutionCodecs.has_value() ? jni::JBoolean::valueOf(value.enableHigherResolutionCodecs.value()) : nullptr,
        value.targetBitRate.has_value() ? jni::JDouble::valueOf(value.targetBitRate.value()) : nullptr,
        value.fileType.has_value() ? JRecorderFileType::fromCpp(value.fileType.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::camera
