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

import com.its.op.entity.its.rse.TbRseCtlrSttsHs;
import com.its.op.entity.its.rse.TbRseCtlrSttsHsKey;
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 TbRseCtlrSttsHsRepository extends JpaRepository<TbRseCtlrSttsHs, TbRseCtlrSttsHsKey>, JpaSpecificationExecutor<TbRseCtlrSttsHs> {

    @Query("select p from TbRseCtlrSttsHs p")
    List<TbRseCtlrSttsHs> findAll();

    @Query("select p from TbRseCtlrSttsHs p")
    List<TbRseCtlrSttsHs> findAllList();

    @Query("select p from TbRseCtlrSttsHs p inner join fetch p.rse where p.crtnDt between :fromDt and :toDt and p.rseCtlrNmbr in :ids")
    List<TbRseCtlrSttsHs> findAllByDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("ids") List<Long> ids);

    @Query("select p from TbRseCtlrSttsHs p inner join fetch p.rse " +
            " where p.crtnDt between :fromDt and :toDt " +
            "   and (p.cmncSttsCd <> 'CMS0' or p.cboxDoorSttsCd <> 'CDS0' or p.cboxTmpr > 40)" +
            "   and p.rseCtlrNmbr in :ids")
    List<TbRseCtlrSttsHs> findAllFailByDateRange(@Param("fromDt") String fromDt, @Param("toDt") String toDt, @Param("ids") List<Long> ids);

}
