package com.viettel.campaign.repository.ccms_full;

import com.viettel.campaign.model.ccms_full.TimeRangeDialMode;
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;

import java.util.List;

/**
 * @author anhvd_itsol
 */

@Repository
public interface TimeRangeDialModeRepository extends JpaRepository<TimeRangeDialMode, Long> {

    List<TimeRangeDialMode> findTimeRangeDialModeByCampaignIdAndCompanySiteId(Long campaignId, Long companySiteId);

    @Query(value = "SELECT * FROM TIME_RANGE_DIAL_MODE r " +
            "WHERE r.CAMPAIGN_ID = :campaignId AND r.COMPANY_SITE_ID = :companySiteId AND TO_CHAR(r.START_TIME,'HH24:MI:SS') <= TO_CHAR(SYSDATE,'HH24:MI:SS')", nativeQuery = true)
    TimeRangeDialMode findDialModeAtCurrent(@Param("campaignId") Long campaignId, @Param("companySiteId") Long companySiteId);

    void deleteAllByCampaignIdAndCompanySiteId(Long campaignId, Long companySiteId);
}
