package com.viettel.campaign.repository;

import com.viettel.campaign.model.CustomerList;
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.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

public interface CustomerListRepository extends JpaRepository<CustomerList, Long> {

    CustomerList findCustomerListByCustomerListId(long customerListId);

    CustomerList findByCustomerListCode(String customerListCode);

    @Modifying
    @Query("delete from CustomerList c where c.customerListId in (:ids)")
    int deleteIds(@Param("ids") List<Long> ids);

    @Query("select c from CustomerList c where c.customerListCode=:customerListCode or c.customerListName=:customerListName or c.createAt >:dateFrom and c.createAt <:dateTo or c.createAt=:dateFrom or c.createAt=:dateTo")
    Page<CustomerList> searchCustomerList(@Param("customerListCode") String customerListCode, @Param("customerListName") String customerListName, @Param("dateFrom") Date dateFrom, @Param("dateTo") Date dateTo, Pageable pageable);
}
