///
/// TradeExecutionResult.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2025 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

// Forward declaration of `Trade` to properly resolve imports.
namespace margelo::nitro::rncandle { struct Trade; }

#include "Trade.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::rncandle {

  /**
   * A struct which can be represented as a JavaScript object (TradeExecutionResult).
   */
  struct TradeExecutionResult {
  public:
    std::optional<Trade> trade     SWIFT_PRIVATE;
    std::optional<std::string> error     SWIFT_PRIVATE;

  public:
    TradeExecutionResult() = default;
    explicit TradeExecutionResult(std::optional<Trade> trade, std::optional<std::string> error): trade(trade), error(error) {}
  };

} // namespace margelo::nitro::rncandle

namespace margelo::nitro {

  // C++ TradeExecutionResult <> JS TradeExecutionResult (object)
  template <>
  struct JSIConverter<margelo::nitro::rncandle::TradeExecutionResult> final {
    static inline margelo::nitro::rncandle::TradeExecutionResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::rncandle::TradeExecutionResult(
        JSIConverter<std::optional<margelo::nitro::rncandle::Trade>>::fromJSI(runtime, obj.getProperty(runtime, "trade")),
        JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "error"))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::rncandle::TradeExecutionResult& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, "trade", JSIConverter<std::optional<margelo::nitro::rncandle::Trade>>::toJSI(runtime, arg.trade));
      obj.setProperty(runtime, "error", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.error));
      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 (!JSIConverter<std::optional<margelo::nitro::rncandle::Trade>>::canConvert(runtime, obj.getProperty(runtime, "trade"))) return false;
      if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "error"))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
