///
/// JOutputSpec.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 "OutputSpec.hpp"

#include "ColorRange.hpp"
#include "JColorRange.hpp"
#include "JVideoCodec.hpp"
#include "JVideoContainer.hpp"
#include "VideoCodec.hpp"
#include "VideoContainer.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::videopipeline {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct OutputSpec by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    OutputSpec toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldPath = clazz->getField<jni::JString>("path");
      jni::local_ref<jni::JString> path = this->getFieldValue(fieldPath);
      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);
      static const auto fieldFps = clazz->getField<jni::JDouble>("fps");
      jni::local_ref<jni::JDouble> fps = this->getFieldValue(fieldFps);
      static const auto fieldBitrate = clazz->getField<jni::JDouble>("bitrate");
      jni::local_ref<jni::JDouble> bitrate = this->getFieldValue(fieldBitrate);
      static const auto fieldCodec = clazz->getField<JVideoCodec>("codec");
      jni::local_ref<JVideoCodec> codec = this->getFieldValue(fieldCodec);
      static const auto fieldContainer = clazz->getField<JVideoContainer>("container");
      jni::local_ref<JVideoContainer> container = this->getFieldValue(fieldContainer);
      static const auto fieldColorRange = clazz->getField<JColorRange>("colorRange");
      jni::local_ref<JColorRange> colorRange = this->getFieldValue(fieldColorRange);
      return OutputSpec(
        path->toStdString(),
        width != nullptr ? std::make_optional(width->value()) : std::nullopt,
        height != nullptr ? std::make_optional(height->value()) : std::nullopt,
        fps != nullptr ? std::make_optional(fps->value()) : std::nullopt,
        bitrate != nullptr ? std::make_optional(bitrate->value()) : std::nullopt,
        codec != nullptr ? std::make_optional(codec->toCpp()) : std::nullopt,
        container != nullptr ? std::make_optional(container->toCpp()) : std::nullopt,
        colorRange != nullptr ? std::make_optional(colorRange->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<JOutputSpec::javaobject> fromCpp(const OutputSpec& value) {
      using JSignature = JOutputSpec(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JVideoCodec>, jni::alias_ref<JVideoContainer>, jni::alias_ref<JColorRange>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.path),
        value.width.has_value() ? jni::JDouble::valueOf(value.width.value()) : nullptr,
        value.height.has_value() ? jni::JDouble::valueOf(value.height.value()) : nullptr,
        value.fps.has_value() ? jni::JDouble::valueOf(value.fps.value()) : nullptr,
        value.bitrate.has_value() ? jni::JDouble::valueOf(value.bitrate.value()) : nullptr,
        value.codec.has_value() ? JVideoCodec::fromCpp(value.codec.value()) : nullptr,
        value.container.has_value() ? JVideoContainer::fromCpp(value.container.value()) : nullptr,
        value.colorRange.has_value() ? JColorRange::fromCpp(value.colorRange.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::videopipeline
