///
/// JRecorderSettings.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 "RecorderSettings.hpp"

#include "HybridLocationSpec.hpp"
#include "JHybridLocationSpec.hpp"
#include <memory>
#include <optional>
#include <string>

namespace margelo::nitro::camera {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct RecorderSettings by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    RecorderSettings toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldLocation = clazz->getField<JHybridLocationSpec::JavaPart>("location");
      jni::local_ref<JHybridLocationSpec::JavaPart> location = this->getFieldValue(fieldLocation);
      static const auto fieldFilePath = clazz->getField<jni::JString>("filePath");
      jni::local_ref<jni::JString> filePath = this->getFieldValue(fieldFilePath);
      static const auto fieldMaxDuration = clazz->getField<jni::JDouble>("maxDuration");
      jni::local_ref<jni::JDouble> maxDuration = this->getFieldValue(fieldMaxDuration);
      static const auto fieldMaxFileSize = clazz->getField<jni::JDouble>("maxFileSize");
      jni::local_ref<jni::JDouble> maxFileSize = this->getFieldValue(fieldMaxFileSize);
      return RecorderSettings(
        location != nullptr ? std::make_optional(location->getJHybridLocationSpec()) : std::nullopt,
        filePath != nullptr ? std::make_optional(filePath->toStdString()) : std::nullopt,
        maxDuration != nullptr ? std::make_optional(maxDuration->value()) : std::nullopt,
        maxFileSize != nullptr ? std::make_optional(maxFileSize->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<JRecorderSettings::javaobject> fromCpp(const RecorderSettings& value) {
      using JSignature = JRecorderSettings(jni::alias_ref<JHybridLocationSpec::JavaPart>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.location.has_value() ? std::dynamic_pointer_cast<JHybridLocationSpec>(value.location.value())->getJavaPart() : nullptr,
        value.filePath.has_value() ? jni::make_jstring(value.filePath.value()) : nullptr,
        value.maxDuration.has_value() ? jni::JDouble::valueOf(value.maxDuration.value()) : nullptr,
        value.maxFileSize.has_value() ? jni::JDouble::valueOf(value.maxFileSize.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::camera
