package com.petshop.backend.repository;

import com.petshop.backend.entity.StoreLocation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface StoreRepository extends JpaRepository<StoreLocation, Long> {

    @Query("SELECT s FROM StoreLocation s WHERE " +
           "LOWER(s.storeName) LIKE LOWER(CONCAT('%', :q, '%')) OR " +
           "LOWER(s.address) LIKE LOWER(CONCAT('%', :q, '%'))")
    Page<StoreLocation> searchStores(@Param("q") String query, Pageable pageable);
}
