///
/// JMediaInfoMedia.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once

#include <fbjni/fbjni.h>
#include "MediaInfoMedia.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::nitromediakit {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct MediaInfoMedia by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    MediaInfoMedia toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldDurationMs = clazz->getField<jni::JDouble>("durationMs");
      jni::local_ref<jni::JDouble> durationMs = this->getFieldValue(fieldDurationMs);
      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 fieldFps = clazz->getField<jni::JDouble>("fps");
      jni::local_ref<jni::JDouble> fps = this->getFieldValue(fieldFps);
      static const auto fieldFormat = clazz->getField<jni::JString>("format");
      jni::local_ref<jni::JString> format = this->getFieldValue(fieldFormat);
      static const auto fieldSizeBytes = clazz->getField<jni::JDouble>("sizeBytes");
      jni::local_ref<jni::JDouble> sizeBytes = this->getFieldValue(fieldSizeBytes);
      static const auto fieldAudioTracks = clazz->getField<jni::JDouble>("audioTracks");
      jni::local_ref<jni::JDouble> audioTracks = this->getFieldValue(fieldAudioTracks);
      static const auto fieldVideoTracks = clazz->getField<jni::JDouble>("videoTracks");
      jni::local_ref<jni::JDouble> videoTracks = this->getFieldValue(fieldVideoTracks);
      return MediaInfoMedia(
        durationMs != nullptr ? std::make_optional(durationMs->value()) : std::nullopt,
        width != nullptr ? std::make_optional(width->value()) : std::nullopt,
        height != nullptr ? std::make_optional(height->value()) : std::nullopt,
        fps != nullptr ? std::make_optional(fps->value()) : std::nullopt,
        format != nullptr ? std::make_optional(format->toStdString()) : std::nullopt,
        sizeBytes != nullptr ? std::make_optional(sizeBytes->value()) : std::nullopt,
        audioTracks != nullptr ? std::make_optional(audioTracks->value()) : std::nullopt,
        videoTracks != nullptr ? std::make_optional(videoTracks->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<JMediaInfoMedia::javaobject> fromCpp(const MediaInfoMedia& value) {
      return newInstance(
        value.durationMs.has_value() ? jni::JDouble::valueOf(value.durationMs.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.fps.has_value() ? jni::JDouble::valueOf(value.fps.value()) : nullptr,
        value.format.has_value() ? jni::make_jstring(value.format.value()) : nullptr,
        value.sizeBytes.has_value() ? jni::JDouble::valueOf(value.sizeBytes.value()) : nullptr,
        value.audioTracks.has_value() ? jni::JDouble::valueOf(value.audioTracks.value()) : nullptr,
        value.videoTracks.has_value() ? jni::JDouble::valueOf(value.videoTracks.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::nitromediakit
