package de.thpeetz.kontor.media.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import de.thpeetz.kontor.media.data.MediaFile;

public interface MediaFileRepository extends JpaRepository<MediaFile, String> {
    @Query("select m from MediaFile m " +
            "where lower(m.url) like lower(concat('%', :searchTerm, '%')) or lower(m.title) like lower(concat('%', :searchTerm, '%'))")
    List<MediaFile> search(@Param("searchTerm") String searchTerm);

    List<MediaFile> findByShouldDownload(Boolean shouldDownload);

    List<MediaFile> findByReview(Boolean review);

    List<MediaFile> findByReviewAndShouldDownload(Boolean review, Boolean shouldDownload);

    MediaFile findByUrl(String url);

    @Query("select m from MediaFile m " +
            "where lower(m.url) like lower(concat('%', :searchTerm, '%')) or lower(m.title) like lower(concat('%', :searchTerm, '%')) " +
            "AND m.review=:review AND m.shouldDownload=:download")
    List<MediaFile> search(
        @Param("searchTerm") String searchTerm, 
        @Param("review") boolean searchReview, 
        @Param("download") boolean searchDownload);
}
