///
/// JBatteryPowerState.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 "BatteryPowerState.hpp"

#include "BatteryState.hpp"
#include "JBatteryState.hpp"

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct BatteryPowerState by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    BatteryPowerState toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldBatteryLevel = clazz->getField<double>("batteryLevel");
      double batteryLevel = this->getFieldValue(fieldBatteryLevel);
      static const auto fieldBatteryState = clazz->getField<JBatteryState>("batteryState");
      jni::local_ref<JBatteryState> batteryState = this->getFieldValue(fieldBatteryState);
      static const auto fieldLowPowerMode = clazz->getField<jboolean>("lowPowerMode");
      jboolean lowPowerMode = this->getFieldValue(fieldLowPowerMode);
      return BatteryPowerState(
        batteryLevel,
        batteryState->toCpp(),
        static_cast<bool>(lowPowerMode)
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JBatteryPowerState::javaobject> fromCpp(const BatteryPowerState& value) {
      using JSignature = JBatteryPowerState(double, jni::alias_ref<JBatteryState>, jboolean);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.batteryLevel,
        JBatteryState::fromCpp(value.batteryState),
        value.lowPowerMode
      );
    }
  };

} // namespace margelo::nitro::one
