package com.drumonii.loltrollbuild.rest;

import com.drumonii.loltrollbuild.model.SummonerSpell;
import com.drumonii.loltrollbuild.model.SummonerSpell.GameMode;
import com.drumonii.loltrollbuild.repository.SummonerSpellsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.data.web.PageableDefault;
import org.springframework.data.web.PagedResourcesAssembler;
import org.springframework.hateoas.PagedResources;
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.Resources;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.stream.Collectors;

import static org.springframework.data.domain.ExampleMatcher.StringMatcher.CONTAINING;
import static org.springframework.hateoas.mvc.BasicLinkBuilder.linkToCurrentMapping;

/**
 * Repository REST controller for {@link SummonerSpell}s.
 */
@RestController
@RequestMapping("/${spring.data.rest.base-path}/summoner-spells")
@RepositoryRestController
public class SummonerSpellsRestController {

	@Autowired
	private SummonerSpellsRepository summonerSpellsRepository;

	@Autowired
	private PagedResourcesAssembler<SummonerSpell> pagedAssembler;

	/**
	 * Gets a {@link PagedResources} of {@link SummonerSpell} {@link Resource} from the pagination and search parameters.
	 *
	 * @param pageable the {@link Pageable}
	 * @param summonerSpell the search {@link SummonerSpell} to define as the QBE
	 * @return the {@link PagedResources} of {@link SummonerSpell} {@link Resource}
	 */
	@GetMapping
	public PagedResources<Resource<SummonerSpell>> getSummonerSpells(
			@PageableDefault(size = 20, sort = "name", direction = Direction.ASC) Pageable pageable,
			SummonerSpell summonerSpell) {
		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
				.withMatcher("name", matcher -> matcher.stringMatcher(CONTAINING))
				.withIgnoreCase()
				.withIgnorePaths("id")
				.withIgnoreNullValues();
		Example<SummonerSpell> example = Example.of(summonerSpell, exampleMatcher);
		return pagedAssembler.toResource(summonerSpellsRepository.findAll(example, pageable));
	}

	/**
	 * Gets a {@link Resources} of {@link SummonerSpell} {@link Resource} for the troll build based on the specified
	 * {@link GameMode}. See {@link SummonerSpellsRepository#forTrollBuild(GameMode mode)} for details on data retrieved.
	 *
	 * @param mode the {@link GameMode} to get eligible {@link SummonerSpell}s for the troll build
	 * @return the {@link Resources} of {@link SummonerSpell} {@link Resource}
	 */
	@GetMapping(value = "/for-troll-build")
	public Resources<Resource<SummonerSpell>> getForTrollBuild(@RequestParam GameMode mode) {
		return new Resources<>(summonerSpellsRepository.forTrollBuild(mode).stream()
				.map(spell -> new Resource<>(spell))
				.collect(Collectors.toList()), linkToCurrentMapping().withSelfRel());
	}

}

@@ -3132,16 +3132,20 @@
 llBuild(
+%0A%09%09%09
 @Request
@@ -3149,16 +3149,60 @@
 estParam
+(required = false, defaultValue = %22CLASSIC%22)
  GameMod

Set request param default value to CLASSIC game mode