package de.thpeetz.kontor.tysc.repository;

import de.thpeetz.kontor.tysc.data.Card;
import de.thpeetz.kontor.tysc.data.CardSet;
import de.thpeetz.kontor.tysc.data.Rooster;
import de.thpeetz.kontor.tysc.data.Vendor;
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;

public interface CardRepository extends JpaRepository<Card, String> {

    @Query("SELECT c FROM Card c WHERE c.vendor = ?1 AND c.cardSet = ?2 and c.rooster = ?3 and c.cardNumber = ?4 and c.year = ?5")
    Card search(Vendor vendor, CardSet cardset, Rooster rooster, int cardNumber, int year);

    @Query("select c from Card c " +
        "where str(c.cardNumber) like lower(concat('%', :searchTerm, '%')) ")
    List<Card> search(@Param("searchTerm") String searchTerm);
}

