///
/// JRawPixelData.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 "RawPixelData.hpp"

#include "JPixelFormat.hpp"
#include "PixelFormat.hpp"
#include <NitroModules/ArrayBuffer.hpp>
#include <NitroModules/JArrayBuffer.hpp>

namespace margelo::nitro::image {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct RawPixelData by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    RawPixelData 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 fieldPixelFormat = clazz->getField<JPixelFormat>("pixelFormat");
      jni::local_ref<JPixelFormat> pixelFormat = this->getFieldValue(fieldPixelFormat);
      return RawPixelData(
        buffer->cthis()->getArrayBuffer(),
        width,
        height,
        pixelFormat->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<JRawPixelData::javaobject> fromCpp(const RawPixelData& value) {
      using JSignature = JRawPixelData(jni::alias_ref<JArrayBuffer::javaobject>, double, double, jni::alias_ref<JPixelFormat>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JArrayBuffer::wrap(value.buffer),
        value.width,
        value.height,
        JPixelFormat::fromCpp(value.pixelFormat)
      );
    }
  };

} // namespace margelo::nitro::image
