package com.viettel.campaign.repository.ccms_full;

import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.ApParam;
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.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 ApParamRepository extends JpaRepository<ApParam, Long>, ApParamRepositoryCustom {

    Page<ApParam> findAll(Pageable pageable);

    @Query(value = "SELECT p FROM ApParam p WHERE parName LIKE concat('%', :parName, '%') ")
    List<ApParam> findParamByName(@Param("parName") String parName, Pageable pageable);

    @Query(value = "SELECT p FROM ApParam p WHERE status = 1 AND parType LIKE concat('%', :parType, '%') ")
    List<ApParam> findParamByParType(@Param("parType") String parType);

    @Query(value = "FROM  ApParam WHERE status = 1 AND parType = :parType")
    List<ApParam> findAllParam(@Param("parType") String parType);
}
