package com.bayer.burp.repository;

import java.util.Collection;
import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.prepost.PreAuthorize;

import com.bayer.burp.domain.Burp;

@PreAuthorize("hasRole('ROLE_USER')")
public interface BurpRepository extends PagingAndSortingRepository<Burp, Long> {
	
	// http://localhost:8080/burps/search/findByUserName?username=Adam
	List<Burp> findByUserName(@Param("username") String username);
	
	// http://localhost:8080/burps/search/findByUserNameIn?usernames=Adam,Ben
	List<Burp> findByUserNameIn(Collection<String> usernames);
	
	// http://localhost:8080/burps/search/searchBurpsStartingWith?prefix=Best
	@Query("select b from Burp b where b.text like :prefix%")
	List<Burp> searchBurpsStartingWith(@Param("prefix") String prefix);
	
	// http://localhost:8080/burps/search/findFirst8ByOrderByTimestampDesc
	List<Burp> findFirst8ByOrderByTimestampDesc();
	
//	@RestResource(exported = false)
//	Page<Burp> findAll(Pageable pageable);

}
