//
// Created by sebastian on 30.07.26.
//

#ifndef COLORRACE_SCENE_H
#define COLORRACE_SCENE_H
#include <memory>
#include <vector>

#include "Layer.h"
#include "core/animation/events/AnimationMarkerEvent.h"
#include "core/events/EventBus.h"
#include "loader/assets/AssetManager.h"
#include "loader/assets/AssetRequests.h"
#include "loader/assets/LoadedAssets.h"
#include "renderer/entities/Camera.h"


namespace engine {
    class Keyboard;
    class Mouse;
    class InputContextStack;

    class Scene {
    public:
        explicit Scene(engine::InputContextStack& inputStack, engine::Keyboard& keyboard, engine::Mouse& mouse):
            assetManager(std::make_unique<AssetManager>()), m_inputStack(inputStack), m_keyboard(keyboard), m_mouse(mouse)  {}
        virtual ~Scene() = default;
        virtual void onEnter() {}
        virtual void onExit() {
            for (const auto& layer : m_layers) {
                layer->onDetach(m_inputStack);
            }
        }

        void onUpdate(float deltaTime);
        void onRender();

        void onRegisterLoadedAsset(LoadedAsset loadedAsset);

        virtual std::vector<AssetRequest> getRequiredAssets() const { return {}; }
    protected:
        std::vector<std::unique_ptr<Layer>> m_layers;
        EventBus<animation::AnimationMarkerEvent>& getAnimationEventBus() { return m_animationMarkerEventBus; }

        void addLayer(std::unique_ptr<Layer> layer);

        engine::EntityRegistry entityRegistry;
        std::unique_ptr<AssetManager> assetManager;
        InputContextStack& m_inputStack;

        engine::Keyboard& m_keyboard;
        engine::Mouse& m_mouse;

    private:
        EventBus<animation::AnimationMarkerEvent> m_animationMarkerEventBus;
    };
}


#endif //COLORRACE_SCENE_H
