class CompetitionSetupMilestoneServiceImpl implements CompetitionSetupMilestoneService {

    @Override
    public List<Error> validateMilestoneDates(Map<String, GenericMilestoneRowForm> milestonesFormEntries) {
        List<Error> errors =  new ArrayList<>();
        milestonesFormEntries.values().forEach(milestone -> {

            Integer day = milestone.getDay();
            Integer month = milestone.getMonth();
            Integer year = milestone.getYear();
            String fieldName = "milestone-" + milestone.getMilestoneNameType().toUpperCase();
            String fieldValidationError = milestone.getMilestoneType().getMilestoneDescription();
            if(!validTimeOfMiddayMilestone(milestone)) {
                errors.add(fieldError(fieldName, "", "error.milestone.invalid", fieldValidationError));
            }

            boolean dateFieldsIncludeNull = (day == null || month == null || year == null);
            if((dateFieldsIncludeNull || !isMilestoneDateValid(day, month, year))) {
                errors.add(fieldError(fieldName, "", "error.milestone.invalid", fieldValidationError));
            }
        });
        return errors;
    }

}