///
/// JClipTransform.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 "ClipTransform.hpp"

#include "CropRect.hpp"
#include "JCropRect.hpp"
#include <optional>

namespace margelo::nitro::videopipeline {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct ClipTransform by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    ClipTransform toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldRotate = clazz->getField<jni::JDouble>("rotate");
      jni::local_ref<jni::JDouble> rotate = this->getFieldValue(fieldRotate);
      static const auto fieldFlipH = clazz->getField<jni::JBoolean>("flipH");
      jni::local_ref<jni::JBoolean> flipH = this->getFieldValue(fieldFlipH);
      static const auto fieldFlipV = clazz->getField<jni::JBoolean>("flipV");
      jni::local_ref<jni::JBoolean> flipV = this->getFieldValue(fieldFlipV);
      static const auto fieldCrop = clazz->getField<JCropRect>("crop");
      jni::local_ref<JCropRect> crop = this->getFieldValue(fieldCrop);
      return ClipTransform(
        rotate != nullptr ? std::make_optional(rotate->value()) : std::nullopt,
        flipH != nullptr ? std::make_optional(static_cast<bool>(flipH->value())) : std::nullopt,
        flipV != nullptr ? std::make_optional(static_cast<bool>(flipV->value())) : std::nullopt,
        crop != nullptr ? std::make_optional(crop->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<JClipTransform::javaobject> fromCpp(const ClipTransform& value) {
      using JSignature = JClipTransform(jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JCropRect>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.rotate.has_value() ? jni::JDouble::valueOf(value.rotate.value()) : nullptr,
        value.flipH.has_value() ? jni::JBoolean::valueOf(value.flipH.value()) : nullptr,
        value.flipV.has_value() ? jni::JBoolean::valueOf(value.flipV.value()) : nullptr,
        value.crop.has_value() ? JCropRect::fromCpp(value.crop.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::videopipeline
