package de.avatic.taric.repository;

import de.avatic.taric.model.Geo;
import de.avatic.taric.model.GeoGroup;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.Optional;

@Repository
public interface GeoRepository extends CrudRepository<Geo, Integer> {

    @Query("SELECT * FROM geo WHERE iso_3166_code = :code AND (end_date IS NULL OR end_date >= CURRENT_DATE)")
    Optional<Geo> findByIso3166Code(@Param("code") String code);


    @Query("SELECT * FROM geo_group WHERE geo_group_code = '1011'")
    Optional<GeoGroup> findErgaOmnes();
}