///
/// JPurchaseState.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 "PurchaseState.hpp"

namespace margelo::nitro::iap {

  using namespace facebook;

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

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

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

} // namespace margelo::nitro::iap
