package com.viettel.campaign.repository;

import com.viettel.campaign.model.Campaign;
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 CampaignRepository extends JpaRepository<Campaign, Long>, CampaignRepositoryCustom {

    @Query("SELECT COUNT(c.campaignId) " +
            " FROM Campaign c JOIN CampaignCustomer cc ON c.campaignId = cc.campaignId " +
            " WHERE cc.companySiteId = :pCompanySiteId " +
            " AND cc.status = 1 " +
            " AND cc.recallTime <= sysdate " +
            " AND cc.agentId = :pAgentId")
    Long countRecallCustomer(@Param("pCompanySiteId") Long pCompanySiteId, @Param("pAgentId") Long pAgentId);
}
