// ============================================================================
// ABSTRACT GAME BASE CLASS
// ============================================================================
// Defines the interface all games must implement
// Provides polymorphic game architecture for modular design

#ifndef GAME_H
#define GAME_H

#include <stdint.h>
#include "input_event.h"
#include "../display/low_level_render.h"
#include "../display/low_level_gui.h"

// Forward declaration
class InputManager;

/**
 * @brief Abstract base class for all games
 * 
 * Games inherit from this class and implement the three core methods:
 * - init(): Set up initial game state
 * - update(): Process input events and update game logic
 * - draw(): Render the game to the display buffer
 * 
 * The main loop in basic1.cpp calls these methods polymorphically,
 * allowing different games to run with the same infrastructure.
 */
class Game {
public:
    enum class Type {
        BASE,
        MONOPOLY_DICE,
        MONOPOLY_PROPERTY,
        MONOPOLY_BOARD,
        MONOPOLY_CHANCE,
        MONOPOLY_COMMUNITY_CHEST,
        MONOPOLY_TURN,
        MONOPOLY_PAYMENT
    };

    /**
     * @brief Construct a new Game
     * @param width Display width in pixels
     * @param height Display height in pixels
     * @param renderer Pointer to low-level rendering interface
     * @param gui Pointer to GUI drawing primitives
     * @param input_manager Pointer to input manager for capability queries
     */
    Game(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager)
        : width(width), height(height), renderer(renderer), gui(gui), input_manager(input_manager) {
    }
    
    /**
     * @brief Virtual destructor for proper cleanup of derived classes
     */
    virtual ~Game() {}
    
    /**
     * @brief Initialize game state
     * 
     * Called once when the game starts. Set up initial values,
     * reset statistics, prepare the game board, etc.
     */
    virtual void init() = 0;
    
    /**
     * @brief Update game state based on input event
     * 
     * Process the input event and update game logic accordingly.
     * This is where game rules, win conditions, state transitions happen.
     * 
     * @param event Input event from InputManager
     * @return true if screen redraw is needed, false otherwise
     */
    virtual bool update(const InputEvent& event) = 0;
    
    /**
     * @brief Draw the game to the display buffer
     * 
     * Render all game graphics using the renderer and gui objects.
     * This is called after update() returns true.
     * The actual screen refresh happens in the main loop on Core 1.
     */
    virtual void draw() = 0;
    
    /**
     * @brief Check if game wants to exit back to launcher
     * 
     * Games can override this to signal they want to return to the menu.
     * Default implementation returns false.
     * 
     * @return true if game wants to exit, false to continue playing
     */
    virtual bool wants_to_exit() const { return false; }

    /**
     * @brief Get the type of game for safe downcasting without RTTI
     */
    virtual Type get_type() const { return Type::BASE; }

protected:
    // Display dimensions
    uint16_t width;
    uint16_t height;
    
    // Rendering interfaces (provided by basic1.cpp)
    LowLevelRenderer* renderer;
    LowLevelGUI* gui;
    
    // Input manager for capability queries
    InputManager* input_manager;
};

#endif // GAME_H
