package objective.taskboard.data;

import static objective.taskboard.monitor.LogbookSectionUtils.getOrClosestBefore;

import java.time.LocalDate;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;

import objective.taskboard.monitor.StrategicalProjectDataSet;
import objective.taskboard.monitor.StrategicalProjectDataSet.MonitorStatus;

public class BudgetScenarioChartData implements ScenarioChartDataSet {
    public Map<LocalDate, Double> worklogByDay = Collections.emptyMap();
    public Map<LocalDate, Double> worklogConservativeProjection = Collections.emptyMap();
    public Map<LocalDate, Double> worklogOptimisticProjection = Collections.emptyMap();
    public Map<LocalDate, Double> budgetTopOnTrack = Collections.emptyMap();
    public Map<LocalDate, Double> budgetBottomOnTrack = Collections.emptyMap();
    public Map<LocalDate, Double> budgetTopAttention = Collections.emptyMap();
    public Map<LocalDate, Double> budgetBottomAttention = Collections.emptyMap();
    public Map<LocalDate, Double> totalBudget = Collections.emptyMap();
    public Map<LocalDate, StrategicalProjectDataSet.MonitorStatus> statusSeries = Collections.emptyMap();
    public Optional<String> computingErrors = Optional.empty();
    public MonitorStatus trendStatus = MonitorStatus.NA;
    
    public Double getTotalAt(LocalDate date) {
        return getOrClosestBefore(totalBudget, date).orElse(0.0);
    }

    @Override
    public Optional<String> getErrorMessage() {
        return computingErrors;
    }

    @Override
    public double getActualAt(LocalDate date) {
        return getOrClosestBefore(worklogConservativeProjection, date)
                .orElseGet(() -> getOrClosestBefore(worklogByDay, date).orElse(0.0));
    }

    @Override
    public double getTopOnTrackAt(LocalDate date) {
        return getOrClosestBefore(budgetTopOnTrack,date).orElse(0.0);
    }

    @Override
    public double getBottomOnTrackAt(LocalDate date) {
        return getOrClosestBefore(budgetBottomOnTrack, date).orElse(0.0);
    }

    @Override
    public MonitorStatus getStatusAt(LocalDate date) {
        return getOrClosestBefore(statusSeries, date).orElse(MonitorStatus.NA);
    }

    @Override
    public MonitorStatus getTrendStatus() {
        return trendStatus;
    }
}
