package com.its.op.dao.repository.its.ifsc;

import com.its.op.entity.its.ifsc.TbReptCngsSect;
import com.its.op.entity.its.ifsc.TbReptCngsSectKey;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TbReptCngsSectRepository extends JpaRepository<TbReptCngsSect, TbReptCngsSectKey>, JpaSpecificationExecutor<TbReptCngsSect> {

    @Query( "select p from TbReptCngsSect p inner join fetch p.ifsc ifsc inner join fetch ifsc.fromNode fn inner join fetch ifsc.toNode tn")
    List<TbReptCngsSect> findAll();

    @Query( "select p from TbReptCngsSect p inner join fetch p.ifsc ifsc inner join fetch ifsc.fromNode fn inner join fetch ifsc.toNode tn " +
            " where p.dcsnYn = :dcsnYn " +
            "   and p.statYm = to_char(sysdate-1, 'YYYYMM') " +
            "   and p.cnfsStrtHm <= to_char(sysdate, 'HH24MI') " +
            "   and p.cnfsEndHm  >= to_char(sysdate, 'HH24MI') " +
            "   and p.dayTypeCd = :dayTypeCd")
    List<TbReptCngsSect> findAllCurrent(@Param("dcsnYn") String dcsnYn, @Param("dayTypeCd") String dayTypeCd);

    @Query("select p from TbReptCngsSect p inner join fetch p.ifsc ifsc inner join fetch ifsc.fromNode fn inner join fetch ifsc.toNode tn " +
           "where p.statYm = :baseMn ")
    List<TbReptCngsSect> findAllAnalByStatYm(@Param("baseMn") String baseMn);

    @Query( "select p from TbReptCngsSect p inner join fetch p.ifsc ifsc inner join fetch ifsc.fromNode fn inner join fetch ifsc.toNode tn " +
            " where p.statYm = :baseMn " +
            "   and p.dayTypeCd = :dayTypeCd")
    List<TbReptCngsSect> findAllAnalByDayTypeCdAndStatYm(@Param("dayTypeCd") String dayTypeCd, @Param("baseMn") String baseMn);
}
