package com.oguerreiro.resilient.activity.registry;

import java.time.Instant;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.stereotype.Component;

import com.oguerreiro.resilient.activity.ActivityDomain;

/**
 * Class that keeps track of all Activities/Tasks in execution. And also have
 * info about progress
 */
@Component
public class ActivityProgressRegistry {
  Map<String, ActivityProgressDescriptor> registry = new ConcurrentHashMap<String, ActivityProgressDescriptor>();

  public ActivityProgressDescriptor progressOf(String activityRegistryKey) {
    return registry.get(activityRegistryKey);
  }

  public ActivityProgressDescriptor progressAdd(ActivityDomain entity) {
    ActivityProgressDescriptor pd = new ActivityProgressDescriptor(Instant.now(), "");
    registry.put(entity.getActivityDomainClass() + "@" + entity.getId(), pd);

    return pd;
  }
}
