package cz.utb.tadis.attacks.repository;

import cz.utb.tadis.attacks.model.Attack;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface AttacksRepository extends JpaRepository<Attack, Long> {

    @Query("SELECT DISTINCT a.city FROM Attack a")
    List<String> findAllDistinctCity();

    @Query("SELECT DISTINCT a.country FROM Attack a")
    List<String> findAllDistinctCountry();

    @Query("SELECT DISTINCT a.softTargetDescription FROM Attack a WHERE a.softTargetDescription IS NOT NULL")
    List<String> findAllDistinctSoftTargetDescription();

    @Query("SELECT DISTINCT a.terroristOrganization FROM Attack a WHERE a.terroristOrganization IS NOT NULL")
    List<String> findAllDistinctTerroristOrganization();

    Optional<Attack> findFirstByOrderByDateAsc();
    Optional<Attack> findFirstByOrderByDateDesc();

}
