class VulnerabilityController implements Constants {

	@RequestMapping(path = "/v1/vulnerabilities/performers", method = RequestMethod.GET)
	public ResponseEntity<Object> getHighestLowestPerformers(@RequestParam("ag") String assetGroup,
			@RequestParam(name = "severity", required = false) String severity) {
		Map<String, Object> response = new HashMap<>();

		List<Map<String, Object>> responseList = new ArrayList<>();
		Map<String, Integer> directorData = vulnerabilityService.getHighestLowestPerformers(assetGroup, severity,
				"org");
		Set<String> keys = directorData.keySet();
		String[] keysArray = keys.toArray(new String[keys.size()]);

		if (keysArray.length >= 10) {

			Map<String, Object> info = new HashMap<>();
			info.put(CATEGORY, HIGHEST);
			List<Map<String, Integer>> directorList = new ArrayList<>();

			for (int i = 0; i < keysArray.length && i < Constants.FIVE; i++) {
				Map<String, Integer> director = new HashMap<>();
				director.put(keysArray[i], directorData.get(keysArray[i]));
				directorList.add(director);
			}
			info.put(DIRECTORS, directorList);
			responseList.add(info);

			info = new HashMap<>();
			info.put(CATEGORY, "Lowest");
			directorList = new ArrayList<>();

			for (int i = keysArray.length - Constants.ONE; i > keysArray.length - Constants.SIX && i >= 0; i--) {
				Map<String, Integer> director = new HashMap<>();
				director.put(keysArray[i], directorData.get(keysArray[i]));
				directorList.add(director);
			}
			info.put(DIRECTORS, directorList);
			responseList.add(info);
		} else {

			if (keysArray.length % 2 == 0) {
				Map<String, Object> info = new HashMap<>();
				info.put(CATEGORY, HIGHEST);
				List<Map<String, Integer>> directorList = new ArrayList<>();

				for (int i = 0; i < keysArray.length / 2; i++) {
					Map<String, Integer> director = new HashMap<>();
					director.put(keysArray[i], directorData.get(keysArray[i]));
					directorList.add(director);
				}
				info.put(DIRECTORS, directorList);
				responseList.add(info);

			} else {

				Map<String, Object> info = new HashMap<>();
				info.put(CATEGORY, HIGHEST);
				List<Map<String, Integer>> directorList = new ArrayList<>();

				for (int i = 0; i < (keysArray.length / 2) + 1; i++) {
					Map<String, Integer> director = new HashMap<>();
					director.put(keysArray[i], directorData.get(keysArray[i]));
					directorList.add(director);
				}
				info.put(DIRECTORS, directorList);
				responseList.add(info);
			}

			Map<String, Object> info = new HashMap<>();
			info.put(CATEGORY, "Lowest");
			List<Map<String, Integer>> directorList = new ArrayList<>();

			for (int i = keysArray.length - Constants.ONE; i > keysArray.length / 2 && i >= 0; i--) {
				Map<String, Integer> director = new HashMap<>();
				director.put(keysArray[i], directorData.get(keysArray[i]));
				directorList.add(director);
			}
			info.put(DIRECTORS, directorList);
			responseList.add(info);
		}
		response.put("response", responseList);
		return ResponseUtils.buildSucessResponse(response);
	}

}