package com.viettel.campaign.repository;

import com.viettel.campaign.model.Customer;
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.stereotype.Repository;

import java.util.List;

@Repository
public interface CustomerRepository extends JpaRepository<Customer, Long> {

    Page<Customer> findAll(Pageable pageable);

    @Query("FROM Customer WHERE name = ?1")
    List<Customer> findByName(String firstName, Pageable pageable);

    @Query("SELECT COUNT(0) FROM Customer t WHERE t.mobileNumber = ?1 and t.siteId = ?2 and t.status = 1 ")
    Long findByMobileNumberAndSiteId(String mobileNumber, Long siteId);

}
