#include "features/watermark/WatermarkFeature.h"

#include <utility>

namespace ta::features::watermark
{
    WatermarkFeature::WatermarkFeature(IWatermarkSettings& settings) noexcept
        : settings_(settings)
    {
    }

    void WatermarkFeature::initialize()
    {
        publish_snapshot();
    }

    void WatermarkFeature::on_application_tick()
    {
        publish_snapshot();
    }

    void WatermarkFeature::reset_session() noexcept
    {
        snapshot_cache_.clear();
    }

    std::optional<WatermarkView> WatermarkFeature::snapshot() const
    {
        return snapshot_cache_.latest();
    }

    void WatermarkFeature::publish_snapshot()
    {
        WatermarkView next = settings_.read();
        snapshot_cache_.publish_if_changed(std::move(next));
    }
}
