#include "Core/Time.h"

#include "Core/TimeObserver.h"

#include <algorithm>
#include <functional>

void Time::attach(TimeObserver* observer) {
    _observers.emplace(observer);
}

void Time::detach(TimeObserver* observer) {
    _observers.erase(observer);
}

Time& Time::operator++() {
    ++_day;
    notify();
    return *this;
}

void Time::notify() const {
    std::ranges::for_each(_observers, std::mem_fn(&TimeObserver::nextDay));
}