///
/// BufferConfig.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 `LivePlaybackParams` to properly resolve imports.
namespace margelo::nitro::video { struct LivePlaybackParams; }
// Forward declaration of `Resolution` to properly resolve imports.
namespace margelo::nitro::video { struct Resolution; }

#include "LivePlaybackParams.hpp"
#include <optional>
#include "Resolution.hpp"

namespace margelo::nitro::video {

  /**
   * A struct which can be represented as a JavaScript object (BufferConfig).
   */
  struct BufferConfig {
  public:
    std::optional<LivePlaybackParams> livePlayback     SWIFT_PRIVATE;
    std::optional<double> minBufferMs     SWIFT_PRIVATE;
    std::optional<double> maxBufferMs     SWIFT_PRIVATE;
    std::optional<double> bufferForPlaybackMs     SWIFT_PRIVATE;
    std::optional<double> bufferForPlaybackAfterRebufferMs     SWIFT_PRIVATE;
    std::optional<double> backBufferDurationMs     SWIFT_PRIVATE;
    std::optional<double> preferredForwardBufferDurationMs     SWIFT_PRIVATE;
    std::optional<double> preferredPeakBitRate     SWIFT_PRIVATE;
    std::optional<Resolution> preferredMaximumResolution     SWIFT_PRIVATE;
    std::optional<double> preferredPeakBitRateForExpensiveNetworks     SWIFT_PRIVATE;
    std::optional<Resolution> preferredMaximumResolutionForExpensiveNetworks     SWIFT_PRIVATE;

  public:
    BufferConfig() = default;
    explicit BufferConfig(std::optional<LivePlaybackParams> livePlayback, std::optional<double> minBufferMs, std::optional<double> maxBufferMs, std::optional<double> bufferForPlaybackMs, std::optional<double> bufferForPlaybackAfterRebufferMs, std::optional<double> backBufferDurationMs, std::optional<double> preferredForwardBufferDurationMs, std::optional<double> preferredPeakBitRate, std::optional<Resolution> preferredMaximumResolution, std::optional<double> preferredPeakBitRateForExpensiveNetworks, std::optional<Resolution> preferredMaximumResolutionForExpensiveNetworks): livePlayback(livePlayback), minBufferMs(minBufferMs), maxBufferMs(maxBufferMs), bufferForPlaybackMs(bufferForPlaybackMs), bufferForPlaybackAfterRebufferMs(bufferForPlaybackAfterRebufferMs), backBufferDurationMs(backBufferDurationMs), preferredForwardBufferDurationMs(preferredForwardBufferDurationMs), preferredPeakBitRate(preferredPeakBitRate), preferredMaximumResolution(preferredMaximumResolution), preferredPeakBitRateForExpensiveNetworks(preferredPeakBitRateForExpensiveNetworks), preferredMaximumResolutionForExpensiveNetworks(preferredMaximumResolutionForExpensiveNetworks) {}
  };

} // namespace margelo::nitro::video

namespace margelo::nitro {

  // C++ BufferConfig <> JS BufferConfig (object)
  template <>
  struct JSIConverter<margelo::nitro::video::BufferConfig> final {
    static inline margelo::nitro::video::BufferConfig fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::video::BufferConfig(
        JSIConverter<std::optional<margelo::nitro::video::LivePlaybackParams>>::fromJSI(runtime, obj.getProperty(runtime, "livePlayback")),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "minBufferMs")),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "maxBufferMs")),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "bufferForPlaybackMs")),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "bufferForPlaybackAfterRebufferMs")),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "backBufferDurationMs")),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "preferredForwardBufferDurationMs")),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "preferredPeakBitRate")),
        JSIConverter<std::optional<margelo::nitro::video::Resolution>>::fromJSI(runtime, obj.getProperty(runtime, "preferredMaximumResolution")),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "preferredPeakBitRateForExpensiveNetworks")),
        JSIConverter<std::optional<margelo::nitro::video::Resolution>>::fromJSI(runtime, obj.getProperty(runtime, "preferredMaximumResolutionForExpensiveNetworks"))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::video::BufferConfig& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, "livePlayback", JSIConverter<std::optional<margelo::nitro::video::LivePlaybackParams>>::toJSI(runtime, arg.livePlayback));
      obj.setProperty(runtime, "minBufferMs", JSIConverter<std::optional<double>>::toJSI(runtime, arg.minBufferMs));
      obj.setProperty(runtime, "maxBufferMs", JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxBufferMs));
      obj.setProperty(runtime, "bufferForPlaybackMs", JSIConverter<std::optional<double>>::toJSI(runtime, arg.bufferForPlaybackMs));
      obj.setProperty(runtime, "bufferForPlaybackAfterRebufferMs", JSIConverter<std::optional<double>>::toJSI(runtime, arg.bufferForPlaybackAfterRebufferMs));
      obj.setProperty(runtime, "backBufferDurationMs", JSIConverter<std::optional<double>>::toJSI(runtime, arg.backBufferDurationMs));
      obj.setProperty(runtime, "preferredForwardBufferDurationMs", JSIConverter<std::optional<double>>::toJSI(runtime, arg.preferredForwardBufferDurationMs));
      obj.setProperty(runtime, "preferredPeakBitRate", JSIConverter<std::optional<double>>::toJSI(runtime, arg.preferredPeakBitRate));
      obj.setProperty(runtime, "preferredMaximumResolution", JSIConverter<std::optional<margelo::nitro::video::Resolution>>::toJSI(runtime, arg.preferredMaximumResolution));
      obj.setProperty(runtime, "preferredPeakBitRateForExpensiveNetworks", JSIConverter<std::optional<double>>::toJSI(runtime, arg.preferredPeakBitRateForExpensiveNetworks));
      obj.setProperty(runtime, "preferredMaximumResolutionForExpensiveNetworks", JSIConverter<std::optional<margelo::nitro::video::Resolution>>::toJSI(runtime, arg.preferredMaximumResolutionForExpensiveNetworks));
      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::video::LivePlaybackParams>>::canConvert(runtime, obj.getProperty(runtime, "livePlayback"))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "minBufferMs"))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "maxBufferMs"))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "bufferForPlaybackMs"))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "bufferForPlaybackAfterRebufferMs"))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "backBufferDurationMs"))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "preferredForwardBufferDurationMs"))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "preferredPeakBitRate"))) return false;
      if (!JSIConverter<std::optional<margelo::nitro::video::Resolution>>::canConvert(runtime, obj.getProperty(runtime, "preferredMaximumResolution"))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "preferredPeakBitRateForExpensiveNetworks"))) return false;
      if (!JSIConverter<std::optional<margelo::nitro::video::Resolution>>::canConvert(runtime, obj.getProperty(runtime, "preferredMaximumResolutionForExpensiveNetworks"))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
