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

#ifndef COLORRACE_COMPONENTPOOL_H
#define COLORRACE_COMPONENTPOOL_H
#include "Entity.h"


namespace engine {
    class IComponentPool {
    public:
        virtual ~IComponentPool() = default;
        virtual void remove(Entity entity) = 0;
        virtual size_t size() = 0;
    };

    template<typename T>
    class ComponentPool : public IComponentPool {
    public:
        void remove(Entity entity) override {
            m_components.erase(entity);
        }

        void insert(Entity entity, T component) {
            m_components[entity] = std::move(component);
        }

        [[nodiscard]] bool has(Entity entity) const {
            return m_components.contains(entity);
        }

        T& get(Entity entity) {
            return m_components.at(entity);
        }

        size_t size() override {
            return m_components.size();
        }

        // Für Iteration in Systemen
        auto begin() { return m_components.begin(); }
        auto end() { return m_components.end(); }

    private:
        std::unordered_map<Entity, T> m_components;
    };
}

#endif //COLORRACE_COMPONENTPOOL_H
