//
// Created by sebastian on 05.08.26.
//

#ifndef COLORRACE_LUDOGAMECONTROLLER_H
#define COLORRACE_LUDOGAMECONTROLLER_H
#include <memory>

#include "LudoGameControllerContext.h"
#include "core/animation/AnimationSystem.h"
#include "core/inputsOutputs/inputs/Keyboard.h"
#include "ecs/systems/PickingSystem.h"
#include "ludo/LudoAiController.h"
#include "ludo/LudoGameMode.h"
#include "ludo/PiecePresenter.h"
#include "ludo/PresentationGameState.h"
#include "ludo/ecs/highlight/HighlightSystem.h"


namespace ludo::GameController {
    class LudoGameController {
    public:
        explicit LudoGameController(LudoGameControllerContext context);
        static std::unique_ptr<LudoGameController> create(LudoGameControllerContext& context);
        void update(float deltaTime, const engine::Mouse& mouse, const engine::Keyboard& keyboard);
        void processEvents();
        bool isBlocking() const;
        const PresentationGameState& getPresentationGameState() const { return m_presentationGameState; }
        engine::PlayerID getLocalPlayer() const { return m_localPlayer; }
    private:
        std::shared_ptr<LudoGameMode> m_gameMode;
        engine::EntityRegistry& m_registry;

        PiecePresenter m_piecePresenter;
        PresentationGameState m_presentationGameState;

        engine::animation::AnimationSystem m_animationSystem;
        HighlightSystem m_highlightSystem;
        engine::PickingSystem m_pickingSystem;

        std::vector<LudoAiController> m_aiControllers;
        engine::PlayerID m_localPlayer;

        void handleInput(const engine::Mouse& mouse, const engine::Keyboard& keyboard);
    };
}


#endif //COLORRACE_LUDOGAMECONTROLLER_H
