package com.its.api.its.repository.ifsc;

import com.its.api.its.model.entity.ifsc.TbReptCngsSect;
import com.its.api.its.model.entity.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 " +
            " where p.dcsnYn = :dcsnYn " +
            "   and p.statYm = to_char(sysdate, '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);
}
