package de.votian.services.repository;

import de.votian.services.entity.ServiceZipCodeAreaAddress;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ServiceZipCodeAreaAddressRepository extends JpaRepository<ServiceZipCodeAreaAddress, Long> {

    @Query("SELECT aa FROM ServiceZipCodeAreaAddress aa, Address ad " +
           "WHERE aa.addressId = ad.id AND aa.headquartersId = :hqId " +
           "AND ad.zipcode = :zipcode AND LOWER(ad.street) LIKE LOWER(CONCAT(:streetPrefix, '%'))")
    List<ServiceZipCodeAreaAddress> findAddressCandidates(@Param("hqId") Long headquartersId,
                                                          @Param("zipcode") String zipcode,
                                                          @Param("streetPrefix") String streetPrefix);
}
