<commit_before>package com.drumonii.loltrollbuild.riot;

import com.drumonii.loltrollbuild.model.Version;
import com.drumonii.loltrollbuild.repository.VersionsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * A {@link RestController} which retrieves the list of versions from Riot's {@code lol-static-data-v1.2} API with the
 * {@code /riot/versions} URL mapping.
 */
@RestController
@RequestMapping("/riot/versions")
public class VersionsRetrieval {

	@Autowired
	private RestTemplate restTemplate;

	@Autowired
	@Qualifier("versions")
	private UriComponents versionsUri;

	@Autowired
	private VersionsRepository versionsRepository;

	/**
	 * Creates a {@link ModelAttribute} of a {@link List} of {@link Version}s from Riot.
	 *
	 * @return a {@link List} of {@link Version}s from Riot
	 */
	@ModelAttribute
	public List<Version> versionsFromResponse() {
		List<Version> versions = Arrays.asList(restTemplate.getForObject(versionsUri.toString(), Version[].class));
		Collections.sort(versions, Collections.reverseOrder());
		return versions;
	}

	/**
	 * Returns the {@link List} of {@link Version}s from Riot for the most current patch.
	 *
	 * @param versions the {@link ModelAttribute} of {@link List} of {@link Version}s from Riot
	 * @return the {@link List} of {@link Version}s from Riot
	 */
	@RequestMapping(method = RequestMethod.GET)
	public List<Version> versions(@ModelAttribute List<Version> versions) {
		return versions;
	}

	/**
	 * Returns the latest patch {@link Version} from Riot.
	 *<commit_msg>Use a ParameterizedTypeReference to get Versions from Riot<commit_after>package com.drumonii.loltrollbuild.riot;

import com.drumonii.loltrollbuild.model.Version;
import com.drumonii.loltrollbuild.repository.VersionsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;

import java.util.Collections;
import java.util.List;

/**
 * A {@link RestController} which retrieves the list of versions from Riot's {@code lol-static-data-v1.2} API with the
 * {@code /riot/versions} URL mapping.
 */
@RestController
@RequestMapping("/riot/versions")
public class VersionsRetrieval {

	@Autowired
	private RestTemplate restTemplate;

	@Autowired
	@Qualifier("versions")
	private UriComponents versionsUri;

	@Autowired
	private VersionsRepository versionsRepository;

	/**
	 * Creates a {@link ModelAttribute} of a {@link List} of {@link Version}s from Riot.
	 *
	 * @return a {@link List} of {@link Version}s from Riot
	 */
	@ModelAttribute
	public List<Version> versionsFromResponse() {
		List<Version> versions = restTemplate.exchange(versionsUri.toString(), HttpMethod.GET, null,
				new ParameterizedTypeReference<List<Version>>() {}).getBody();
		Collections.sort(versions, Collections.reverseOrder());
		return versions;
	}

	/**
	 * Returns the {@link List} of {@link Version}s from Riot for the most current patch.
	 *
	 * @param versions the {@link ModelAttribute} of {@link List} of {@link Version}s from Riot
	 * @return the {@link List} of {@link Version}s from Riot
	 */
	@RequestMapping(method = RequestMethod.GET)
	public List<Version> versions(@ModelAttribute List<Version> versions) {
		return versions;
	}

	/**
	 * Returns the latest patch {@link Version} from Riot.
	 *
{'fraction_non_alphanumeric': 0.11093247588424437, 'fraction_numerical': 0.0009186954524575103, 'mean_word_length': 5.558734939759036, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2497776', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1221, 'n_words': 323}