#pragma once

#include <frostbite2D/graphics/camera.h>
#include <frostbite2D/types/type_math.h>

namespace ns_game {

struct CameraControllerConfig {
  frostbite2D::Rect worldBounds;
  float viewportWidth = 1280.0f;
  float viewportHeight = 720.0f;
  frostbite2D::Rect deadZone = frostbite2D::Rect(420.0f, 0.0f, 340.0f, 720.0f);
  float smoothing = 14.0f;
};

class CameraController {
public:
  void Configure(const CameraControllerConfig& config);
  void SetWorldBounds(const frostbite2D::Rect& worldBounds);
  void SnapToTarget(frostbite2D::Camera& camera,
                    const frostbite2D::Rect& targetBounds);
  void Update(frostbite2D::Camera& camera, const frostbite2D::Rect& targetBounds,
              float deltaTime);

private:
  frostbite2D::Vec2 resolveDesiredPosition(
      const frostbite2D::Vec2& currentPosition,
      const frostbite2D::Rect& targetBounds) const;
  frostbite2D::Vec2 clampToWorld(const frostbite2D::Vec2& position) const;

  CameraControllerConfig config_;
};

} // namespace ns_game
