#include "component.hpp"
#include <algorithm>
#include <cmath>
#include <stdexcept>
namespace asw {
SpeedCommand target_speed(double maximum, double curvature, double mode_factor, double obstacle_distance_m) {
  if (maximum <= 0 || mode_factor <= 0) throw std::invalid_argument("positive limits required");
  double target = maximum * mode_factor / (1 + 3.5 * std::abs(curvature)); bool limited = false;
  if (obstacle_distance_m < 2) { target = 0; limited = true; }
  else if (obstacle_distance_m < 5) { target = std::min(target, maximum * 0.25); limited = true; }
  return {target, limited};
}
}
