package de.thpeetz.kontor.comics.repository;

import java.util.List;

import de.thpeetz.kontor.comics.data.*;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ComicRepository extends JpaRepository<Comic, String> {
    @Query("select c from Comic c " +
            "where lower(c.title) like lower(concat('%', :searchTerm, '%')) ")
    List<Comic> search(@Param("searchTerm") String searchTerm);

    @Query("select c from Comic c " +
            "where lower(c.title) like lower(concat('%', :searchTerm, '%')) " +
            "AND c.currentOrder=:currentOrder AND c.completed=:completed")
    List<Comic> search(@Param("searchTerm") String searchTerm, Boolean currentOrder, Boolean completed);

    Comic findByTitleAndPublisher(String title, Publisher publisher);

    List<Comic> findByTitle(String title);

    List<Comic> findByTitleIgnoreCase(String title);

    List<Comic> findByCurrentOrderAndCompleted(Boolean currentOrder, Boolean completed);

    List<Comic> findByCurrentOrder(Boolean currentOrder);

    List<Comic> findByCompleted(Boolean completed);

    @Query("select c from Comic c " +
            "where lower(c.title) like lower(concat('%', :searchTerm, '%')) AND c.currentOrder=:currentOrder")
    List<Comic> searchAndFilterByCurrentOrder(String searchTerm, Boolean currentOrder);

    @Query("select c from Comic c " +
            "where lower(c.title) like lower(concat('%', :searchTerm, '%')) AND c.completed=:completed")
    List<Comic> searchAndFilterByCompleted(String searchTerm, Boolean completed);
}
