package objective.taskboard.monitor;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static objective.taskboard.monitor.LogbookSectionUtils.formatPercentage;

import java.util.List;

import objective.taskboard.data.LogbookSectionTableDto;
import objective.taskboard.scenario.model.LogbookModel;
import objective.taskboard.scenario.model.WeekParametersModel;

public class ThresholdSectionGenerator implements LogbookSectionGenerator {

    @Override
    public LogbookSectionTableDto generate(LogbookModel logbook) {
        String title = "Thresholds";

        List<List<String>> headers = singletonList(
                asList("Parameter", "Value")
        );

        return new LogbookSectionTableDto(5, title, headers, new RowsBuilder(logbook.weekParameters()).build());
    }

    private static class RowsBuilder {

        final WeekParametersModel weekParameters;

        public RowsBuilder(WeekParametersModel weekParameters) {
            this.weekParameters = weekParameters;
        }

        String scopeThreshold() {
            return formatPercentage(weekParameters.getScopeThreshold());
        }

        String budgetThreshold() {
            return formatPercentage(weekParameters.getBudgetThreshold());
        }

        String timelineThreshold() {
            return formatPercentage(weekParameters.getTimelineThreshold());
        }

        String defectThreshold() {
            return formatPercentage(weekParameters.getDefectThreshold());
        }

        List<String> scopeRow() {
            return asList("On track scope", scopeThreshold());
        }

        List<String> budgetRow() {
            return asList("On track budget", budgetThreshold());
        }

        List<String> timelineRow() {
            return asList("On track timeline", timelineThreshold());
        }

        List<String> defectRow() {
            return asList("On track defect", defectThreshold());
        }

        public List<List<String>> build() {
            return asList(
                    scopeRow()
                    , budgetRow()
                    , timelineRow()
                    , defectRow()
            );
        }
    }
}
