class CompetitionSetupServiceImpl implements CompetitionSetupService {

    @Override
    public ServiceResult<Void> setCompetitionAsReadyToOpen(Long competitionId) {
        CompetitionResource competitionResource = competitionRestService.getCompetitionById(competitionId).getSuccess();
        if (competitionResource.getCompetitionStatus() == CompetitionStatus.READY_TO_OPEN) {
            return serviceSuccess();
        }

        if (isCompetitionReadyToOpen(competitionResource)) {
            return competitionSetupRestService.markAsSetup(competitionId).toServiceResult();
        } else {
            return serviceFailure(new Error("competition.setup.not.ready.to.open", HttpStatus.BAD_REQUEST));
        }
    }

}