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

import com.its.op.entity.its.facility.TbFcltFailAct;
import com.its.op.entity.its.facility.TbFcltFailActKey;
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 TbFcltFailActRepository extends JpaRepository<TbFcltFailAct, TbFcltFailActKey>, JpaSpecificationExecutor<TbFcltFailAct> {

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

    @Query("select p from TbFcltFailAct p where p.useYn = 'Y'")
    List<TbFcltFailAct> findAllList();

    @Query(value = "SELECT NVL(MAX(ACT_SEQ), 0) + 1 AS NEWID FROM TB_FCLT_FAIL_ACT WHERE FAIL_NO = :failNo", nativeQuery = true)
    Long getNewActSeq(@Param("failNo") String failNo);

    @Query("select p from TbFcltFailAct p where p.failNo = :failNo")
    List<TbFcltFailAct> findActListByFailNo(@Param("failNo") String failNo);

    @Query("select count(p.failNo) from TbFcltFailAct p where p.failNo = :failNo")
    Integer findUsageCountById(String failNo);

}
