#ifndef GAME_MGMT_H
#define GAME_MGMT_H

#include <stdint.h>
#include <stdbool.h>

/**
 * @brief System states for the Lasertag devices.
 * These states define the behavior of the device in the network.
 */
typedef enum {
    SYS_STATE_NO_CHANGE = 0x00, /* Placeholder for no state change */
    SYS_STATE_IDLE      = 0x01, /* Device is on but inactive */
    SYS_STATE_LOBBY     = 0x02, /* Discovery phase: Leader sends beacon, Nodes reply */
    SYS_STATE_STARTING  = 0x03, /* Countdown phase before match start */
    SYS_STATE_RUNNING   = 0x04, /* Match is active: IR and local logic enabled */
    SYS_STATE_POST_GAME = 0x05  /* Match ended: Data collection and review */
} sys_state_t;

/**
 * @brief Callback for state changes.
 * Allows apps/modules to react when the system transitions (e.g., UI updates).
 */
typedef void (*game_mgmt_state_cb_t)(sys_state_t new_state);

/**
 * @brief Initialize the game management module.
 * Sets the initial state and prepares timers/workqueues.
 * @return 0 on success.
 */
int game_mgmt_init(void);

/**
 * @brief Set the system state and trigger corresponding actions.
 * Leader: Starts/stops beacons. Nodes: Starts/stops heartbeats.
 * @param state The target state to transition to.
 */
void game_mgmt_set_state(sys_state_t state);

/**
 * @brief Returns the current system state.
 * @return Current sys_state_t value.
 */
sys_state_t game_mgmt_get_state(void);

/** 
 * @brief Set the current game ID.
 * @param id The game ID to set.
 */
void game_mgmt_set_game_id(uint64_t id);

/**
 * @brief Get the current game ID.
 * @return The current game ID.
 */
uint64_t game_mgmt_get_game_id(void);

/**
 * @brief Registers a callback for state changes.
 * @param cb Function to be called on transition.
 */
void game_mgmt_register_state_cb(game_mgmt_state_cb_t cb);

#endif /* GAME_MGMT_H */