///
/// JErrorCode.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 "ErrorCode.hpp"

namespace margelo::nitro::taponpagseguro {

  using namespace facebook;

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

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

  public:
    /**
     * Create a Java/Kotlin-based enum with the given C++ enum's value.
     */
    [[maybe_unused]]
    static jni::alias_ref<JErrorCode> fromCpp(ErrorCode value) {
      static const auto clazz = javaClassStatic();
      switch (value) {
        case ErrorCode::INVALID_RESULT:
          static const auto fieldINVALID_RESULT = clazz->getStaticField<JErrorCode>("INVALID_RESULT");
          return clazz->getStaticFieldValue(fieldINVALID_RESULT);
        case ErrorCode::INVALID_PARAM:
          static const auto fieldINVALID_PARAM = clazz->getStaticField<JErrorCode>("INVALID_PARAM");
          return clazz->getStaticFieldValue(fieldINVALID_PARAM);
        case ErrorCode::UNEXPECTED_ERROR:
          static const auto fieldUNEXPECTED_ERROR = clazz->getStaticField<JErrorCode>("UNEXPECTED_ERROR");
          return clazz->getStaticFieldValue(fieldUNEXPECTED_ERROR);
        case ErrorCode::OPERATION_CANCELED:
          static const auto fieldOPERATION_CANCELED = clazz->getStaticField<JErrorCode>("OPERATION_CANCELED");
          return clazz->getStaticFieldValue(fieldOPERATION_CANCELED);
        case ErrorCode::SERVICE_UNAVAILABLE:
          static const auto fieldSERVICE_UNAVAILABLE = clazz->getStaticField<JErrorCode>("SERVICE_UNAVAILABLE");
          return clazz->getStaticFieldValue(fieldSERVICE_UNAVAILABLE);
        default:
          std::string stringValue = std::to_string(static_cast<int>(value));
          throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
      }
    }
  };

} // namespace margelo::nitro::taponpagseguro
