///
/// JThorShape.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 "ThorShape.hpp"

#include "JThorShapeType.hpp"
#include "ThorShapeType.hpp"
#include <optional>
#include <string>
#include <vector>

namespace margelo::nitro::thor {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct ThorShape by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    ThorShape toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldType = clazz->getField<JThorShapeType>("type");
      jni::local_ref<JThorShapeType> type = this->getFieldValue(fieldType);
      static const auto fieldFill = clazz->getField<jni::JString>("fill");
      jni::local_ref<jni::JString> fill = this->getFieldValue(fieldFill);
      static const auto fieldStroke = clazz->getField<jni::JString>("stroke");
      jni::local_ref<jni::JString> stroke = this->getFieldValue(fieldStroke);
      static const auto fieldStrokeWidth = clazz->getField<jni::JDouble>("strokeWidth");
      jni::local_ref<jni::JDouble> strokeWidth = this->getFieldValue(fieldStrokeWidth);
      static const auto fieldX = clazz->getField<jni::JDouble>("x");
      jni::local_ref<jni::JDouble> x = this->getFieldValue(fieldX);
      static const auto fieldY = clazz->getField<jni::JDouble>("y");
      jni::local_ref<jni::JDouble> y = this->getFieldValue(fieldY);
      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 fieldRx = clazz->getField<jni::JDouble>("rx");
      jni::local_ref<jni::JDouble> rx = this->getFieldValue(fieldRx);
      static const auto fieldRy = clazz->getField<jni::JDouble>("ry");
      jni::local_ref<jni::JDouble> ry = this->getFieldValue(fieldRy);
      static const auto fieldCx = clazz->getField<jni::JDouble>("cx");
      jni::local_ref<jni::JDouble> cx = this->getFieldValue(fieldCx);
      static const auto fieldCy = clazz->getField<jni::JDouble>("cy");
      jni::local_ref<jni::JDouble> cy = this->getFieldValue(fieldCy);
      static const auto fieldRadius = clazz->getField<jni::JDouble>("radius");
      jni::local_ref<jni::JDouble> radius = this->getFieldValue(fieldRadius);
      static const auto fieldX1 = clazz->getField<jni::JDouble>("x1");
      jni::local_ref<jni::JDouble> x1 = this->getFieldValue(fieldX1);
      static const auto fieldY1 = clazz->getField<jni::JDouble>("y1");
      jni::local_ref<jni::JDouble> y1 = this->getFieldValue(fieldY1);
      static const auto fieldX2 = clazz->getField<jni::JDouble>("x2");
      jni::local_ref<jni::JDouble> x2 = this->getFieldValue(fieldX2);
      static const auto fieldY2 = clazz->getField<jni::JDouble>("y2");
      jni::local_ref<jni::JDouble> y2 = this->getFieldValue(fieldY2);
      static const auto fieldPoints = clazz->getField<jni::JArrayDouble>("points");
      jni::local_ref<jni::JArrayDouble> points = this->getFieldValue(fieldPoints);
      static const auto fieldClosed = clazz->getField<jni::JBoolean>("closed");
      jni::local_ref<jni::JBoolean> closed = this->getFieldValue(fieldClosed);
      return ThorShape(
        type->toCpp(),
        fill != nullptr ? std::make_optional(fill->toStdString()) : std::nullopt,
        stroke != nullptr ? std::make_optional(stroke->toStdString()) : std::nullopt,
        strokeWidth != nullptr ? std::make_optional(strokeWidth->value()) : std::nullopt,
        x != nullptr ? std::make_optional(x->value()) : std::nullopt,
        y != nullptr ? std::make_optional(y->value()) : std::nullopt,
        width != nullptr ? std::make_optional(width->value()) : std::nullopt,
        height != nullptr ? std::make_optional(height->value()) : std::nullopt,
        rx != nullptr ? std::make_optional(rx->value()) : std::nullopt,
        ry != nullptr ? std::make_optional(ry->value()) : std::nullopt,
        cx != nullptr ? std::make_optional(cx->value()) : std::nullopt,
        cy != nullptr ? std::make_optional(cy->value()) : std::nullopt,
        radius != nullptr ? std::make_optional(radius->value()) : std::nullopt,
        x1 != nullptr ? std::make_optional(x1->value()) : std::nullopt,
        y1 != nullptr ? std::make_optional(y1->value()) : std::nullopt,
        x2 != nullptr ? std::make_optional(x2->value()) : std::nullopt,
        y2 != nullptr ? std::make_optional(y2->value()) : std::nullopt,
        points != nullptr ? std::make_optional([&]() {
          size_t __size = points->size();
          std::vector<double> __vector(__size);
          points->getRegion(0, __size, __vector.data());
          return __vector;
        }()) : std::nullopt,
        closed != nullptr ? std::make_optional(static_cast<bool>(closed->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<JThorShape::javaobject> fromCpp(const ThorShape& value) {
      using JSignature = JThorShape(jni::alias_ref<JThorShapeType>, jni::alias_ref<jni::JString>, 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<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JArrayDouble>, jni::alias_ref<jni::JBoolean>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JThorShapeType::fromCpp(value.type),
        value.fill.has_value() ? jni::make_jstring(value.fill.value()) : nullptr,
        value.stroke.has_value() ? jni::make_jstring(value.stroke.value()) : nullptr,
        value.strokeWidth.has_value() ? jni::JDouble::valueOf(value.strokeWidth.value()) : nullptr,
        value.x.has_value() ? jni::JDouble::valueOf(value.x.value()) : nullptr,
        value.y.has_value() ? jni::JDouble::valueOf(value.y.value()) : nullptr,
        value.width.has_value() ? jni::JDouble::valueOf(value.width.value()) : nullptr,
        value.height.has_value() ? jni::JDouble::valueOf(value.height.value()) : nullptr,
        value.rx.has_value() ? jni::JDouble::valueOf(value.rx.value()) : nullptr,
        value.ry.has_value() ? jni::JDouble::valueOf(value.ry.value()) : nullptr,
        value.cx.has_value() ? jni::JDouble::valueOf(value.cx.value()) : nullptr,
        value.cy.has_value() ? jni::JDouble::valueOf(value.cy.value()) : nullptr,
        value.radius.has_value() ? jni::JDouble::valueOf(value.radius.value()) : nullptr,
        value.x1.has_value() ? jni::JDouble::valueOf(value.x1.value()) : nullptr,
        value.y1.has_value() ? jni::JDouble::valueOf(value.y1.value()) : nullptr,
        value.x2.has_value() ? jni::JDouble::valueOf(value.x2.value()) : nullptr,
        value.y2.has_value() ? jni::JDouble::valueOf(value.y2.value()) : nullptr,
        value.points.has_value() ? [&]() {
          size_t __size = value.points.value().size();
          jni::local_ref<jni::JArrayDouble> __array = jni::JArrayDouble::newArray(__size);
          __array->setRegion(0, __size, value.points.value().data());
          return __array;
        }() : nullptr,
        value.closed.has_value() ? jni::JBoolean::valueOf(value.closed.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::thor
