///
/// JEncodedImageData.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 "EncodedImageData.hpp"

#include "ImageFormat.hpp"
#include "JImageFormat.hpp"
#include <NitroModules/ArrayBuffer.hpp>
#include <NitroModules/JArrayBuffer.hpp>

namespace margelo::nitro::image {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct EncodedImageData by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    EncodedImageData toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldBuffer = clazz->getField<JArrayBuffer::javaobject>("buffer");
      jni::local_ref<JArrayBuffer::javaobject> buffer = this->getFieldValue(fieldBuffer);
      static const auto fieldWidth = clazz->getField<double>("width");
      double width = this->getFieldValue(fieldWidth);
      static const auto fieldHeight = clazz->getField<double>("height");
      double height = this->getFieldValue(fieldHeight);
      static const auto fieldImageFormat = clazz->getField<JImageFormat>("imageFormat");
      jni::local_ref<JImageFormat> imageFormat = this->getFieldValue(fieldImageFormat);
      return EncodedImageData(
        buffer->cthis()->getArrayBuffer(),
        width,
        height,
        imageFormat->toCpp()
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JEncodedImageData::javaobject> fromCpp(const EncodedImageData& value) {
      using JSignature = JEncodedImageData(jni::alias_ref<JArrayBuffer::javaobject>, double, double, jni::alias_ref<JImageFormat>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JArrayBuffer::wrap(value.buffer),
        value.width,
        value.height,
        JImageFormat::fromCpp(value.imageFormat)
      );
    }
  };

} // namespace margelo::nitro::image
