package com.viettel.campaign.repository.ccms_full;

import com.viettel.campaign.model.ccms_full.CampaignCustomer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface CampaignCustomerRepository extends JpaRepository<CampaignCustomer, Long> {
    @Query(value = "SELECT COUNT(*) " +
            "FROM CAMPAIGN_CUSTOMER CC JOIN CAMPAIGN_COMPLETE_CODE CCC ON CC.CAMPAIGN_ID = CCC.CAMPAIGN_ID " +
            "WHERE CC.STATUS = 3 AND CC.CAMPAIGN_ID = :campaignId AND CC.CUSTOMER_ID = :customerId AND CCC.IS_RECALL = 1 AND CCC.STATUS = 1 ",
            nativeQuery = true)
    Long getCustomerRecall(@Param("campaignId") Long campaignId, @Param("customerId") Long customerId);
}
