@RequestMapping("/{userPseudo}/validateStep4")
  public ResponseEntity<Void> validateStep4(
      @PathVariable("userPseudo") String userPseudo,
      @RequestParam("userHostAndPort") String userHostAndPort) {
    log.info("Validation step 4 for player {} with data {}", userPseudo, userHostAndPort);

    ResponseEntity<Void> result = new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);

    String url = "http://" + userHostAndPort + "/zen/env";

    ResponseEntity<String> responseEntityShouldFail =
        restTemplate.exchange(
            url, HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), String.class);

    byte[] encodedAuth = Base64.encodeBase64("zenika:technozaure".getBytes());
    String authHeader = "Basic " + new String(encodedAuth);

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.set("Authorization", authHeader);
    HttpEntity<String> entity = new HttpEntity<>(headers);

    ResponseEntity<String> responseEntityShouldSucceed =
        restTemplate.exchange(url, HttpMethod.GET, entity, String.class);

    if (responseEntityShouldFail.getStatusCode() != HttpStatus.OK
        && responseEntityShouldSucceed.getStatusCode() == HttpStatus.OK) {
      gameStepRepository.save(new GameStep(userPseudo, Step._4));
      result = new ResponseEntity<Void>(HttpStatus.OK);
      broadcastGameStatus();
    }

    return result;
  }
  @RequestMapping("/{userPseudo}/validateStep3")
  public ResponseEntity<Void> validateStep3(
      @PathVariable("userPseudo") String userPseudo, @RequestParam("secret") String secret) {
    log.info("Validation step 3 for player {} with data {}", userPseudo, secret);

    ResponseEntity<Void> result = new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);

    if (stepConfig.getStep3().equals(secret)) {
      gameStepRepository.save(new GameStep(userPseudo, Step._3));
      result = new ResponseEntity<Void>(HttpStatus.OK);
      broadcastGameStatus();
    }

    return result;
  }
  @RequestMapping("/{userPseudo}/validateStep5")
  public ResponseEntity<Void> validateStep5(
      @PathVariable("userPseudo") String userPseudo, @RequestParam("secret") String secret) {
    log.info("Validation step 5 for player {} with data {}", userPseudo, secret);

    ResponseEntity<Void> result = new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);

    if (environment.getProperty("git.commit.id.abbrev").equals(secret)) {
      gameStepRepository.save(new GameStep(userPseudo, Step._5));
      result = new ResponseEntity<Void>(HttpStatus.OK);
      broadcastGameStatus();
    }

    return result;
  }
  @RequestMapping("/{userPseudo}/validateStep1")
  public ResponseEntity<Void> validateStep1(
      @PathVariable("userPseudo") String userPseudo,
      @RequestParam("userHostAndPort") String userHostAndPort) {
    log.info("Validation step 1 for player {} with data {}", userPseudo, userHostAndPort);
    ResponseEntity<Void> result = new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);

    ResponseEntity<String> responseEntity =
        restTemplate.getForEntity("http://" + userHostAndPort + "/zen/health", String.class);

    if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
      gameStepRepository.save(new GameStep(userPseudo, Step._1));
      result = new ResponseEntity<Void>(HttpStatus.OK);
      broadcastGameStatus();
    }

    broadcastGameStatus();
    return result;
  }
  @RequestMapping("/gameStatus")
  public ResponseEntity<GameStatus> broadcastGameStatus() {
    GameStatus gameStatus = new GameStatus();

    Iterable<GameStep> gameSteps = gameStepRepository.findAll();

    List<GameStep> collect = StreamSupport.stream(gameSteps.spliterator(), false).collect(toList());

    Map<String, List<GameStep>> gameStepByUser =
        StreamSupport.stream(gameSteps.spliterator(), false)
            .collect(Collectors.groupingBy(GameStep::getUserPseudo));

    for (Map.Entry<String, List<GameStep>> gameStepByUserEntry : gameStepByUser.entrySet()) {
      UserGameStatus userGameStatus = new UserGameStatus();

      userGameStatus.setPseudo(gameStepByUserEntry.getKey());

      Map<Step, List<GameStep>> gameStepByStep =
          gameStepByUserEntry.getValue().stream().collect(Collectors.groupingBy(GameStep::getStep));

      for (Map.Entry<Step, List<GameStep>> gameStepByStepEntry : gameStepByStep.entrySet()) {
        gameStepByStepEntry
            .getValue()
            .stream()
            .min(Comparator.comparing(GameStep::getInstant))
            .ifPresent(
                gameStep -> {
                  userGameStatus
                      .getStepInfos()
                      .add(new StepInfo(gameStep.getStep(), gameStep.getInstant()));
                });
      }

      gameStatus.getUserGameStatus().add(userGameStatus);
    }

    webSocketTemplate.convertAndSend("/topic/gameStatus", gameStatus);
    return new ResponseEntity<GameStatus>(gameStatus, HttpStatus.OK);
  }