package com.its.api.its.repository.facility;

import com.its.api.its.model.entity.facility.TbFcltFailHs;
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 TbFcltFailHsRepository extends JpaRepository<TbFcltFailHs, String>, JpaSpecificationExecutor<TbFcltFailHs> {

    @Query("select p from TbFcltFailHs p where p.fcltId = :fcltId")
    List<TbFcltFailHs> findAllFailList(@Param("fcltId") String fcltId);

    @Query(value = "SELECT TO_NUMBER(LPAD(NVL(MAX(SUBSTR(FAIL_HS_SEQ, -4)), '0000') + 1, 4, '0')) AS NEWID " +
                   "  FROM TB_FCLT_FAIL_HS                                                                 " +
                   " WHERE SUBSTR(FAIL_HS_SEQ, 1, 6) = '202203'", nativeQuery = true)
    Integer findNewHsSeq(@Param("currYear") String currYear);
}
