package com.viettel.campaign.repository.ccms_full;

import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.CampaignAgent;
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 org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
@Transactional(DataSourceQualify.CCMS_FULL)
public interface CampaignAgentRepository extends JpaRepository<CampaignAgent, Long> {

    @Query(value = "SELECT campaign_agent_seq.nextval FROM DUAL", nativeQuery = true)
    Long getNextSeqId();

    List<CampaignAgent> findByCampaignIdAndAgentId(Long campaignId, Long agentId);

    @Modifying
    @Query("delete from CampaignAgent c where c.campaignAgentId in (:p_campaign_agent_id)")
    int deleteCampaignAgent(@Param("p_campaign_agent_id") List<Long> campaignAgentId);
}
