//
// Created by sebastian on 29.07.26.
//

#ifndef COLORRACE_GAMELAYER_H
#define COLORRACE_GAMELAYER_H
#include <utility>

#include "core/animation/AnimationSystem.h"
#include "core/audio/AudioDevice.h"
#include "core/audio/SoundBuffer.h"
#include "core/inputsOutputs/controller/CameraController.h"
#include "ecs/EntityRegistry.h"
#include "ecs/systems/PickingSystem.h"
#include "layer/Layer.h"
#include "../ludo/BoardLayout.h"
#include "../ludo/LudoAiController.h"
#include "../ludo/PiecePresenter.h"
#include "renderer/MeshRenderer.h"
#include "renderer/RenderQueue.h"
#include "utils/openglWrapper/GLRenderState.h"
#include "../ludo/LudoGameMode.h"
#include "../ludo/PresentationGameState.h"
#include "../ludo/ecs/highlight/HighlightSystem.h"
#include "gameController/LudoGameController.h"

class GameLayer: public engine::Layer {
public:
    GameLayer(
        engine::EventBus<engine::animation::AnimationMarkerEvent>& animationEventbus,
        std::shared_ptr<ludo::LudoGameMode> gameMode,
        engine::EntityRegistry& entityRegistry,
        std::shared_ptr<engine::Camera> cam,
        std::shared_ptr<engine::PointLight> light,
        engine::Keyboard& keyboard, engine::Mouse& mouse,
        engine::EventBus<ludo::LudoEvent>& eventBus,
        engine::AssetManager& assetManager
        )
            :
        Layer(keyboard, mouse, animationEventbus),
        m_gameMode(gameMode),
        m_eventBus(eventBus),
        m_entityRegistry(entityRegistry),
        m_camera(std::move(cam)),
        m_pointLight(std::move(light)),
        m_assetManager(assetManager)
    {}


    void onUpdate(float deltaTime) override;
    void onRender() override;
protected:
    void onAttachImpl() override;
    void onDetachImpl() override;
private:
    engine::GLRenderState m_renderState;
    engine::RenderQueue m_renderQueue;
    engine::EntityRegistry& m_entityRegistry;
    engine::EventBus<ludo::LudoEvent>& m_eventBus;
    std::shared_ptr<engine::PointLight> m_pointLight;
    std::shared_ptr<engine::Camera> m_camera;
    std::unique_ptr<engine::MeshRenderer> m_renderer;
    std::unique_ptr<engine::CameraController> m_cameraController;
    std::shared_ptr<ludo::LudoGameMode> m_gameMode;
    std::unique_ptr<engine::audio::SoundBuffer> m_soundBuffer;


    void renderHud();
    std::unique_ptr<ludo::GameController::LudoGameController> m_GameController;
    engine::AssetManager& m_assetManager;
};

#endif //COLORRACE_GAMELAYER_H
