///
/// JIapPlatform.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 "IapPlatform.hpp"

namespace margelo::nitro::iap {

  using namespace facebook;

  /**
   * The C++ JNI bridge between the C++ enum "IapPlatform" and the the Kotlin enum "IapPlatform".
   */
  struct JIapPlatform final: public jni::JavaClass<JIapPlatform> {
  public:
    static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/iap/IapPlatform;";

  public:
    /**
     * Convert this Java/Kotlin-based enum to the C++ enum IapPlatform.
     */
    [[maybe_unused]]
    [[nodiscard]]
    IapPlatform toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldOrdinal = clazz->getField<int>("value");
      int ordinal = this->getFieldValue(fieldOrdinal);
      return static_cast<IapPlatform>(ordinal);
    }

  public:
    /**
     * Create a Java/Kotlin-based enum with the given C++ enum's value.
     */
    [[maybe_unused]]
    static jni::alias_ref<JIapPlatform> fromCpp(IapPlatform value) {
      static const auto clazz = javaClassStatic();
      switch (value) {
        case IapPlatform::IOS:
          static const auto fieldIOS = clazz->getStaticField<JIapPlatform>("IOS");
          return clazz->getStaticFieldValue(fieldIOS);
        case IapPlatform::ANDROID:
          static const auto fieldANDROID = clazz->getStaticField<JIapPlatform>("ANDROID");
          return clazz->getStaticFieldValue(fieldANDROID);
        default:
          std::string stringValue = std::to_string(static_cast<int>(value));
          throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
      }
    }
  };

} // namespace margelo::nitro::iap
