///
/// JColor.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 "Color.hpp"

#include <optional>

namespace margelo::nitro::image {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct Color by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    Color toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldR = clazz->getField<double>("r");
      double r = this->getFieldValue(fieldR);
      static const auto fieldG = clazz->getField<double>("g");
      double g = this->getFieldValue(fieldG);
      static const auto fieldB = clazz->getField<double>("b");
      double b = this->getFieldValue(fieldB);
      static const auto fieldA = clazz->getField<jni::JDouble>("a");
      jni::local_ref<jni::JDouble> a = this->getFieldValue(fieldA);
      return Color(
        r,
        g,
        b,
        a != nullptr ? std::make_optional(a->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<JColor::javaobject> fromCpp(const Color& value) {
      using JSignature = JColor(double, double, double, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.r,
        value.g,
        value.b,
        value.a.has_value() ? jni::JDouble::valueOf(value.a.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::image
