// src/game/state.h
#pragma once
#include "mbed.h"
#include "../render/player.h"

constexpr auto CRAWL_DURATION = 300ms;

enum class PlayerState { Walk, Run, Crawl1, Crawl2 };

struct FrameSelection {
  MovementType movement;
  int frame_index;
};

class WalkingState {
private:
  PlayerState current_state = PlayerState::Walk;
  Timer state_timer;
  int walk_index = 0;   // cycles 0‑6
  int run_index  = 0;   // cycles 0‑6
  int crawl1_index = 0;  // cycles 0‑1
  int crawl2_index = 0;  // cycles 0‑1
  float phase = 0.0f;

public:
  void update();
  void start_crawl(PlayerState crawl_type);

  void set_motion_state_for_speed(int player_speed, int ground_speed);
  void toggle_walk_frame(float player_speed, int tick_counter);

  FrameSelection get_frame_selection() const;
  PlayerState get_state() const { return current_state; }

  void set_state(PlayerState s);
};
