class CompetitionSetupMilestoneServiceImpl implements CompetitionSetupMilestoneService {

    @Override
    public ServiceResult<Void> updateMilestonesForCompetition(List<MilestoneResource> milestones, Map<String, GenericMilestoneRowForm> milestoneEntries, Long competitionId) {
        List<MilestoneResource> updatedMilestones = new ArrayList<>();

        milestones.forEach(milestoneResource -> {
            GenericMilestoneRowForm milestoneWithUpdate = milestoneEntries.getOrDefault(milestoneResource.getType().name(), null);

            if(milestoneWithUpdate != null) {
                ZonedDateTime temp = milestoneWithUpdate.getMilestoneAsZonedDateTime();
                if (temp != null) {
                    milestoneResource.setDate(temp);
                    updatedMilestones.add(milestoneResource);
                } else {
                    milestoneRestService
                            .resetMilestone(milestoneResource)
                            .getSuccess();
                }
            }
        });

        return milestoneRestService.updateMilestones(updatedMilestones).toServiceResult();
    }

}