class ResultsService {

    public GetRegistrationResultsPayload getResultsFor(Registration registration) {
        GetRegistrationResultsPayload payload = new GetRegistrationResultsPayload();
        payload.setRegistration(registration);

        List<Run> runs = runEntityService.getAllWithRegistration(registration);
        int maxRunsPerRegistration = registration.getEvent().getMaxRunsPerRegistration();
        List<ScoredRun> scoredRuns = new ArrayList<>(runs.size());
        for (Run run : runs) {
            if (scoredRuns.size() >= maxRunsPerRegistration) {
                break;
            }
            ScoredRun scoredRun = runScoringInteractor.score(run);
            if (scoredRun != null) {
                scoredRuns.add(scoredRun);
            }
        }
        payload.setScoredRuns(scoredRuns);

        payload.setScore(scoredRuns.stream()
                                 .min(Comparator.comparing(ScoredRun::getRawTimeScored))
                                 .orElse(null));

        return payload;
    }

    @Inject public  ResultsService(
            RunEntityService runEntityService,
            RunScoringInteractor runScoringInteractor
    );

}