package com.petshop.backend.repository;

import com.petshop.backend.entity.Supplier;
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 SupplierRepository extends JpaRepository<Supplier, Long> {

    @Query("SELECT s FROM Supplier s WHERE " +
           "LOWER(s.supCompany) LIKE LOWER(CONCAT('%', :q, '%')) OR " +
           "LOWER(s.supContactFirstName) LIKE LOWER(CONCAT('%', :q, '%')) OR " +
           "LOWER(s.supContactLastName) LIKE LOWER(CONCAT('%', :q, '%'))")
    Page<Supplier> searchSuppliers(@Param("q") String query, Pageable pageable);
}
