#pragma once

#include "IObserver.hpp"
#include <vector>
#include <algorithm>

namespace TSE
{
    class IObservable
    {
    private:
        std::vector<IObserver*> objectsToNotify;

    public:
        inline void Observe(IObserver* observer)
        {
            objectsToNotify.push_back(observer);
        };
        inline void StopObserve(IObserver* observer)
        {
            auto it = std::find(objectsToNotify.begin(), objectsToNotify.end(), observer);
            if(it != objectsToNotify.end())
                objectsToNotify.erase(it);
        };

    protected:
        inline void TriggerObserver(void* data)
        {
            for (auto &&observer : objectsToNotify)
            {
                observer->OnObserved(data);
            }
        };
    };
} // namespace TSE
