package de.avatic.lcc.service.calculation.execution;

import de.avatic.lcc.dto.calculation.CalculationStatus;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicReference;

@Service
public class CalculationStatusService {

    AtomicReference<HashMap<Integer, CalculationStatus>> status = new AtomicReference<>();

    public CalculationStatus getCalculationStatus(int processId) {
        return status.get().get(processId);
    }

    public void addCalculationStatus(int statusId, CalculationStatus calculationStatus) {
        HashMap<Integer, CalculationStatus> map = status.get();
        if(map == null){
            map = new HashMap<>();
        }
        map.put(statusId, calculationStatus);
        status.set(map);
    }

    public void removeCalculationStatus(int statusId) {
        HashMap<Integer, CalculationStatus> map = status.get();
        if(map != null){
            map.remove(statusId);
        }
    }

    public Integer schedule(ArrayList<Integer> calculationIds) {
        //TODO
        return 1;
    }
}
