#pragma once

#include "../core/input_state.h"
#include "../movement/platform_world.h"

#include <frostbite2D/2d/actor.h>
#include <frostbite2D/2d/sprite.h>
#include <frostbite2D/types/type_math.h>

namespace ns_game {

class PlayerActor : public frostbite2D::Actor {
public:
  PlayerActor();

  void SetMovementWorld(const PlatformWorld* world);
  void OnUpdate(float deltaTime) override;

private:
  enum class AnimState {
    Idle,
    Run,
    Punch
  };

  void loadSprites();
  void updateInput();
  void updatePhysics(float deltaTime);
  void updateAnimation(float deltaTime);
  void setAnimState(AnimState state);
  frostbite2D::Ptr<frostbite2D::Sprite> activeSprite() const;

  const PlatformWorld* movementWorld_ = nullptr;
  InputStateProvider inputProvider_;
  PlatformMover platformMover_;
  frostbite2D::Ptr<frostbite2D::Sprite> idleSprite_;
  frostbite2D::Ptr<frostbite2D::Sprite> runSprite_;
  frostbite2D::Ptr<frostbite2D::Sprite> punchSprite_;

  frostbite2D::Vec2 velocity_;
  AnimState animState_ = AnimState::Idle;
  float animTimer_ = 0.0f;
  float attackTimer_ = 0.0f;
  int frameIndex_ = 0;
  bool facingLeft_ = false;
  bool grounded_ = false;
};

} // namespace ns_game
