///
/// JImageTransformOptions.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 "ImageTransformOptions.hpp"

#include "ImageCrop.hpp"
#include "ImageResize.hpp"
#include "JImageCrop.hpp"
#include "JImageResize.hpp"
#include "JOneImageFlip.hpp"
#include "JOneImageFormat.hpp"
#include "OneImageFlip.hpp"
#include "OneImageFormat.hpp"
#include <optional>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct ImageTransformOptions by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    ImageTransformOptions toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldCrop = clazz->getField<JImageCrop>("crop");
      jni::local_ref<JImageCrop> crop = this->getFieldValue(fieldCrop);
      static const auto fieldResize = clazz->getField<JImageResize>("resize");
      jni::local_ref<JImageResize> resize = this->getFieldValue(fieldResize);
      static const auto fieldRotate = clazz->getField<jni::JDouble>("rotate");
      jni::local_ref<jni::JDouble> rotate = this->getFieldValue(fieldRotate);
      static const auto fieldFlip = clazz->getField<JOneImageFlip>("flip");
      jni::local_ref<JOneImageFlip> flip = this->getFieldValue(fieldFlip);
      static const auto fieldFormat = clazz->getField<JOneImageFormat>("format");
      jni::local_ref<JOneImageFormat> format = this->getFieldValue(fieldFormat);
      static const auto fieldQuality = clazz->getField<jni::JDouble>("quality");
      jni::local_ref<jni::JDouble> quality = this->getFieldValue(fieldQuality);
      return ImageTransformOptions(
        crop != nullptr ? std::make_optional(crop->toCpp()) : std::nullopt,
        resize != nullptr ? std::make_optional(resize->toCpp()) : std::nullopt,
        rotate != nullptr ? std::make_optional(rotate->value()) : std::nullopt,
        flip != nullptr ? std::make_optional(flip->toCpp()) : std::nullopt,
        format->toCpp(),
        quality != nullptr ? std::make_optional(quality->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<JImageTransformOptions::javaobject> fromCpp(const ImageTransformOptions& value) {
      using JSignature = JImageTransformOptions(jni::alias_ref<JImageCrop>, jni::alias_ref<JImageResize>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JOneImageFlip>, jni::alias_ref<JOneImageFormat>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.crop.has_value() ? JImageCrop::fromCpp(value.crop.value()) : nullptr,
        value.resize.has_value() ? JImageResize::fromCpp(value.resize.value()) : nullptr,
        value.rotate.has_value() ? jni::JDouble::valueOf(value.rotate.value()) : nullptr,
        value.flip.has_value() ? JOneImageFlip::fromCpp(value.flip.value()) : nullptr,
        JOneImageFormat::fromCpp(value.format),
        value.quality.has_value() ? jni::JDouble::valueOf(value.quality.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
