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

#pragma once

#if __has_include(<NitroModules/JSIConverter.hpp>)
#include <NitroModules/JSIConverter.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/NitroDefines.hpp>)
#include <NitroModules/NitroDefines.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/JSIHelpers.hpp>)
#include <NitroModules/JSIHelpers.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
#include <NitroModules/PropNameIDCache.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif



#include <string>

namespace margelo::nitro::nitroark {

  /**
   * A struct which can be represented as a JavaScript object (OnchainTransactionInfo).
   */
  struct OnchainTransactionInfo final {
  public:
    std::string txid     SWIFT_PRIVATE;
    std::string tx_hex     SWIFT_PRIVATE;
    bool has_onchain_fee     SWIFT_PRIVATE;
    double onchain_fee_sat     SWIFT_PRIVATE;
    double balance_change_sat     SWIFT_PRIVATE;
    bool has_confirmation     SWIFT_PRIVATE;
    double confirmation_height     SWIFT_PRIVATE;
    std::string confirmation_hash     SWIFT_PRIVATE;

  public:
    OnchainTransactionInfo() = default;
    explicit OnchainTransactionInfo(std::string txid, std::string tx_hex, bool has_onchain_fee, double onchain_fee_sat, double balance_change_sat, bool has_confirmation, double confirmation_height, std::string confirmation_hash): txid(txid), tx_hex(tx_hex), has_onchain_fee(has_onchain_fee), onchain_fee_sat(onchain_fee_sat), balance_change_sat(balance_change_sat), has_confirmation(has_confirmation), confirmation_height(confirmation_height), confirmation_hash(confirmation_hash) {}

  public:
    friend bool operator==(const OnchainTransactionInfo& lhs, const OnchainTransactionInfo& rhs) = default;
  };

} // namespace margelo::nitro::nitroark

namespace margelo::nitro {

  // C++ OnchainTransactionInfo <> JS OnchainTransactionInfo (object)
  template <>
  struct JSIConverter<margelo::nitro::nitroark::OnchainTransactionInfo> final {
    static inline margelo::nitro::nitroark::OnchainTransactionInfo fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::nitroark::OnchainTransactionInfo(
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "txid"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "tx_hex"))),
        JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "has_onchain_fee"))),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onchain_fee_sat"))),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "balance_change_sat"))),
        JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "has_confirmation"))),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confirmation_height"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confirmation_hash")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitroark::OnchainTransactionInfo& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "txid"), JSIConverter<std::string>::toJSI(runtime, arg.txid));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "tx_hex"), JSIConverter<std::string>::toJSI(runtime, arg.tx_hex));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "has_onchain_fee"), JSIConverter<bool>::toJSI(runtime, arg.has_onchain_fee));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "onchain_fee_sat"), JSIConverter<double>::toJSI(runtime, arg.onchain_fee_sat));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "balance_change_sat"), JSIConverter<double>::toJSI(runtime, arg.balance_change_sat));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "has_confirmation"), JSIConverter<bool>::toJSI(runtime, arg.has_confirmation));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "confirmation_height"), JSIConverter<double>::toJSI(runtime, arg.confirmation_height));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "confirmation_hash"), JSIConverter<std::string>::toJSI(runtime, arg.confirmation_hash));
      return obj;
    }
    static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
      if (!value.isObject()) {
        return false;
      }
      jsi::Object obj = value.getObject(runtime);
      if (!nitro::isPlainObject(runtime, obj)) {
        return false;
      }
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "txid")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "tx_hex")))) return false;
      if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "has_onchain_fee")))) return false;
      if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onchain_fee_sat")))) return false;
      if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "balance_change_sat")))) return false;
      if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "has_confirmation")))) return false;
      if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confirmation_height")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "confirmation_hash")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
