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

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

#include <string>
#include "ToolParameter.hpp"
#include <vector>
#include <NitroModules/AnyMap.hpp>
#include <NitroModules/Promise.hpp>
#include <functional>

namespace margelo::nitro::mlxreactnative {

  /**
   * A struct which can be represented as a JavaScript object (ToolDefinition).
   */
  struct ToolDefinition {
  public:
    std::string name     SWIFT_PRIVATE;
    std::string description     SWIFT_PRIVATE;
    std::vector<ToolParameter> parameters     SWIFT_PRIVATE;
    std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>& /* args */)> handler     SWIFT_PRIVATE;

  public:
    ToolDefinition() = default;
    explicit ToolDefinition(std::string name, std::string description, std::vector<ToolParameter> parameters, std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>& /* args */)> handler): name(name), description(description), parameters(parameters), handler(handler) {}
  };

} // namespace margelo::nitro::mlxreactnative

namespace margelo::nitro {

  // C++ ToolDefinition <> JS ToolDefinition (object)
  template <>
  struct JSIConverter<margelo::nitro::mlxreactnative::ToolDefinition> final {
    static inline margelo::nitro::mlxreactnative::ToolDefinition fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::mlxreactnative::ToolDefinition(
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "name")),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "description")),
        JSIConverter<std::vector<margelo::nitro::mlxreactnative::ToolParameter>>::fromJSI(runtime, obj.getProperty(runtime, "parameters")),
        JSIConverter<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>&)>>::fromJSI(runtime, obj.getProperty(runtime, "handler"))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mlxreactnative::ToolDefinition& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, "name", JSIConverter<std::string>::toJSI(runtime, arg.name));
      obj.setProperty(runtime, "description", JSIConverter<std::string>::toJSI(runtime, arg.description));
      obj.setProperty(runtime, "parameters", JSIConverter<std::vector<margelo::nitro::mlxreactnative::ToolParameter>>::toJSI(runtime, arg.parameters));
      obj.setProperty(runtime, "handler", JSIConverter<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>&)>>::toJSI(runtime, arg.handler));
      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, "name"))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "description"))) return false;
      if (!JSIConverter<std::vector<margelo::nitro::mlxreactnative::ToolParameter>>::canConvert(runtime, obj.getProperty(runtime, "parameters"))) return false;
      if (!JSIConverter<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::shared_ptr<AnyMap>>>>>(const std::shared_ptr<AnyMap>&)>>::canConvert(runtime, obj.getProperty(runtime, "handler"))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
