package fr.titionfire.ffsaf.domain.service;

import jakarta.enterprise.context.ApplicationScoped;

import java.util.HashMap;

@ApplicationScoped
public class UpdateService { // For public result page
    static HashMap<Long, Long> lastUpdate = new HashMap<>();

    public void setNewData(long id) {
        lastUpdate.put(id, System.currentTimeMillis());
    }

    public boolean needUpdate(long id, long last_update) {
        if (!lastUpdate.containsKey(id)) {
            lastUpdate.put(id, System.currentTimeMillis() - 5000);
            return true;
        }

        return lastUpdate.getOrDefault(id, 0L) > last_update;
    }
}
